diff --git a/lib/hbc/cli/create.rb b/lib/hbc/cli/create.rb index 713e030f5b1..7a850490554 100644 --- a/lib/hbc/cli/create.rb +++ b/lib/hbc/cli/create.rb @@ -17,6 +17,12 @@ class Hbc::CLI::Create < Hbc::CLI::Base exec_editor cask_path end + # for mocking + # todo: add an :exec parameter to SystemCommand + def self.exec_editor(*args) + Hbc::Utils.exec_editor(*args) + end + def self.template(cask_token) <<-EOS.undent cask :v1 => '#{cask_token}' do diff --git a/lib/hbc/cli/edit.rb b/lib/hbc/cli/edit.rb index b0ff82a5150..b6264de0a46 100644 --- a/lib/hbc/cli/edit.rb +++ b/lib/hbc/cli/edit.rb @@ -12,6 +12,12 @@ class Hbc::CLI::Edit < Hbc::CLI::Base exec_editor cask_path end + # for mocking. + # todo: add an :exec parameter to SystemCommand + def self.exec_editor(*args) + Hbc::Utils.exec_editor(*args) + end + def self.help "edits the given Cask" end diff --git a/lib/hbc/utils.rb b/lib/hbc/utils.rb index 8280ee28b6d..b56355e3187 100644 --- a/lib/hbc/utils.rb +++ b/lib/hbc/utils.rb @@ -132,6 +132,12 @@ module Hbc::Utils return cmd_pn end + def self.exec_editor(*args) + editor = [ *ENV.values_at('HOMEBREW_EDITOR', 'VISUAL', 'EDITOR'), + *%w{mate edit vim /usr/bin/vim} ].compact.first + exec(editor, *args) + end + # originally from Homebrew puts_columns def self.stringify_columns items, star_items=[] return if items.empty? diff --git a/lib/vendor/homebrew-fork/utils.rb b/lib/vendor/homebrew-fork/utils.rb index bde56a1621c..63feefb59ca 100644 --- a/lib/vendor/homebrew-fork/utils.rb +++ b/lib/vendor/homebrew-fork/utils.rb @@ -44,31 +44,6 @@ def curl *args safe_system curl, *args end -def which_editor - editor = ENV.values_at('HOMEBREW_EDITOR', 'VISUAL', 'EDITOR').compact.first - # If an editor wasn't set, try to pick a sane default - return editor unless editor.nil? - - # Find Textmate - return 'mate' if Hbc::Utils.which "mate" - # Find BBEdit / TextWrangler - return 'edit' if Hbc::Utils.which "edit" - # Find vim - return 'vim' if Hbc::Utils.which "vim" - # Default to standard vim - return '/usr/bin/vim' -end - -def exec_editor *args - safe_exec(which_editor, *args) -end - -def safe_exec cmd, *args - # This buys us proper argument quoting and evaluation - # of environment variables in the cmd parameter. - exec "/bin/sh", "-c", "#{cmd} \"$@\"", "--", *args -end - def ignore_interrupts(opt = nil) std_trap = trap("INT") do puts "One sec, just cleaning up" unless opt == :quietly