Module: Git::Story::Utils

Includes:
FileUtils::Verbose
Included in:
App, App, Setup, Setup
Defined in:
lib/git/story/utils.rb

Instance Method Summary collapse

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: '? ', **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) ⇒ 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