Module: Thor::Actions

Included in:
Thegarage::Gitx::Cli::BaseCommand
Defined in:
lib/thegarage/gitx/extensions/thor.rb

Instance Method Summary collapse

Instance Method Details

#ask_editor(initial_text = '', editor = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/thegarage/gitx/extensions/thor.rb', line 19

def ask_editor(initial_text = '', editor = nil)
  editor ||= ENV['EDITOR'] || 'vi'
  Tempfile.open('comment.md') do |f|
    f << initial_text
    f.flush

    flags = case editor
    when 'mate', 'emacs', 'subl'
      '-w'
    when 'mvim'
      '-f'
    else
      ''
    end
    pid = fork { exec([editor, flags, f.path].join(' ')) }
    Process.waitpid(pid)
    File.read(f.path)
  end
end

#run_cmd(cmd, options = {}) ⇒ Object

execute a shell command and raise an error if non-zero exit code is returned return the string output from the command



7
8
9
10
11
12
13
# File 'lib/thegarage/gitx/extensions/thor.rb', line 7

def run_cmd(cmd, options = {})
  say "$ #{cmd}"
  output = `#{cmd}`
  success = $CHILD_STATUS.to_i == 0
  fail "#{cmd} failed" unless success || options[:allow_failure]
  output
end