module BranchIOCLI::Helper::Methods

Public Instance Methods

clear() click to toggle source

Clear the screen and move the cursor to the top using highline

# File lib/branch_io_cli/helper/methods.rb, line 34
def clear
  say "\e[2J\e[H"
end
confirm(question, default_value) click to toggle source

Ask a yes/no question with a default

# File lib/branch_io_cli/helper/methods.rb, line 39
def confirm(question, default_value)
  yn_opts = default_value ? "Y/n" : "y/N"
  value = ask "#{question} (#{yn_opts}) ", nil

  # Convert to true/false
  dummy_option = Configuration::Option.new({})
  value = dummy_option.convert(value)

  return default_value if value.nil? || value.kind_of?(String)
  value
end
sh(*command) click to toggle source

Execute a shell command with reporting. The command itself is logged, then output from both stdout and stderr, then a success or failure message. Raises CommandError on error. No redirection occurs.

@param command [String, Array] A shell command to execute

# File lib/branch_io_cli/helper/methods.rb, line 28
def sh(*command)
  status = STDOUT.sh(*command)
  raise CommandError, [command, status] unless status.success?
end