class Envo::Cli::Runner

Constants

Commands
USAGE
VERSION_TEXT

Attributes

host[R]
payload[R]

Public Class Methods

new(host, payload) click to toggle source
# File lib/envo/cli/runner.rb, line 4
def initialize(host, payload)
  @host = host
  @payload = payload
end

Public Instance Methods

check_help_ver(argv) click to toggle source
# File lib/envo/cli/runner.rb, line 75
def check_help_ver(argv)
  raise Error.new USAGE if argv.empty?
  case argv[0]
  when '--help', '-h', '-?'
    print_help
    true
  when '--version'
    print_version
    true
  else
    false
  end
end
do_run(argv) click to toggle source
# File lib/envo/cli/runner.rb, line 89
def do_run(argv)
  return if check_help_ver(argv)

  parser = CliParser.new(Opts)
  Commands.each { |cmd| cmd.register_cli_parser(parser) }
  parsed = parser.parse(argv)

  ctx = Context.new(@host, @log, Opts::Defaults)
  ctx.execute(parsed)

  patch = ctx.state.diff

  return if patch.empty?

  patch.removed.each { |name|
    @payload.puts @host.shell.cmd_unset_env_var(name)
    puts @host.shell.cmd_unset_env_var(name)
  }
  patch.changed.each { |name, val|
    @payload.puts @host.shell.cmd_set_env_var(name, val)
    puts @host.shell.cmd_set_env_var(name, val)
  }
  patch.added.each { |name, val|
    @payload.puts @host.shell.cmd_set_env_var(name, val)
    puts @host.shell.cmd_set_env_var(name, val)
  }
end
print_help() click to toggle source
print_version() click to toggle source
run(argv) click to toggle source
# File lib/envo/cli/runner.rb, line 117
def run(argv)
  @log = Logger.new
  begin
    do_run(argv)
    return 0
  rescue Error => e
    @log.error e.message
    return 1
  end
end