Module: Git::Story::Utils
Instance Method Summary collapse
- #ask(prompt: '? ', **options, &block) ⇒ Object
- #capture(command) ⇒ Object
- #sh(*a, error: true) ⇒ Object
Instance Method Details
#ask(prompt: '? ', **options, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/git/story/utils.rb', line 22 def ask(prompt: '? ', **, &block) response = [:preset] unless response if [:default] $stdout.print prompt % [:default] response = $stdin.gets.chomp response.empty? and response = [:default] else $stdout.print prompt response = $stdin.gets end end response = response.to_s.chomp if block block.(response) else response end end |
#capture(command) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/git/story/utils.rb', line 15 def capture(command) @debug and STDERR.puts("Executing #{command.inspect}") result = `#{command}` @debug and STDERR.puts("Result\n#{result}") result end |
#sh(*a, error: true) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/git/story/utils.rb', line 6 def sh(*a, error: true) @debug and STDERR.puts("Executing #{a * ' '}") system(*a) if error && !$?.success? STDERR.puts ("Failed with rc #{$?.exitstatus}: " + a.join(' ')).red exit $?.exitstatus end end |