module Git::Story::Utils

Public Instance Methods

ask(prompt: '? ', **options, &block) click to toggle source
# File lib/git/story/utils.rb, line 22
def ask(prompt: '? ', **options, &block)
  response = options[:preset]
  unless response
    if options[:default]
      $stdout.print prompt % options[:default]
      response = $stdin.gets.chomp
      response.empty? and response = options[: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) click to toggle source
# 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) click to toggle source
# 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