Module: Wagemage::Helpers

Included in:
Wagemage, CLI
Defined in:
lib/wagemage/helpers.rb

Instance Method Summary collapse

Instance Method Details

#askObject



8
9
10
# File 'lib/wagemage/helpers.rb', line 8

def ask
  STDIN.gets.chomp
end

#command(cmd, chdir: Dir.pwd, error: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wagemage/helpers.rb', line 16

def command(cmd, chdir: Dir.pwd, error: false)
  stdout, stderr, status = Open3.capture3(cmd, chdir: chdir)

  unless status.success?
    error ? (raise Error, stderr) : warning(stderr)
  end

  {
    stdout: stdout,
    stderr: stderr,
    status: status
  }
end

#say(message, space: false, color: :white) ⇒ Object



3
4
5
6
# File 'lib/wagemage/helpers.rb', line 3

def say(message, space: false, color: :white)
  puts if space
  puts message.colorize(color.to_sym)
end

#warning(message) ⇒ Object



12
13
14
# File 'lib/wagemage/helpers.rb', line 12

def warning(message)
  say(message, color: :red)
end