class DotUsage::Command

Public Class Methods

new(cmd) click to toggle source
# File lib/dot_usage.rb, line 69
def initialize(cmd)
  @cmd = cmd
end

Public Instance Methods

run(options) click to toggle source
# File lib/dot_usage.rb, line 73
def run(options)
  if options.yes
    run_without_prompt(options)
  else
    run_with_prompt(options)
  end
end

Private Instance Methods

execute(cmd) click to toggle source
# File lib/dot_usage.rb, line 83
def execute(cmd)
  system cmd
end
run_with_prompt(options) click to toggle source
# File lib/dot_usage.rb, line 93
def run_with_prompt(options)
  print "> Run `#{@cmd}` [Y/n]? "

  go = case gets.chomp
  when "y", "Y", "yes", ""
    true
  when "n", "N", "no"
    false
  else
    STDERR.puts '> Invalid choice!'
    false
  end

  if go
    execute @cmd
  else
    puts "Quitting!"
    1
  end
end
run_without_prompt(options) click to toggle source
# File lib/dot_usage.rb, line 87
def run_without_prompt(options)
  puts "> Running `#{@cmd}`"

  execute @cmd
end