Class: ESP::CommandsTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/esp/commands/commands_tasks.rb

Overview

This is a class which takes in an esp command and initiates the appropriate initiation sequence.

Warning: This class mutates ARGV because some commands require manipulating it before they are run.

Constant Summary collapse

HELP_MESSAGE =
<<-EOT
Usage: esp COMMAND [environment] [ARGS]

The ESP commands are:
 console                      Start the ESP console (short-cut alias: "c")
 add_external_account         Adds external accounts to ESP (short-cut alias: "a")

All commands can be run with -h (or --help) for more information.
EOT
COMMAND_WHITELIST =
%w(console add_external_account version help)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CommandsTasks

Returns a new instance of CommandsTasks.



22
23
24
# File 'lib/esp/commands/commands_tasks.rb', line 22

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

:nodoc:



8
9
10
# File 'lib/esp/commands/commands_tasks.rb', line 8

def argv
  @argv
end

Instance Method Details

#add_external_accountObject



44
45
46
# File 'lib/esp/commands/commands_tasks.rb', line 44

def 
  require_command!("add_external_account")
end

#consoleObject



37
38
39
40
41
42
# File 'lib/esp/commands/commands_tasks.rb', line 37

def console
  require_command!("console")

  print_banner
  ESP::Console.new.start
end

#helpObject



53
54
55
# File 'lib/esp/commands/commands_tasks.rb', line 53

def help
  write_help_message
end

#run_command!(command) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/esp/commands/commands_tasks.rb', line 26

def run_command!(command)
  command = parse_command(command)
  if COMMAND_WHITELIST.include?(command)
    set_env!
    require_relative '../../../lib/esp_sdk'
    send(command)
  else
    write_error_message(command)
  end
end

#versionObject



48
49
50
51
# File 'lib/esp/commands/commands_tasks.rb', line 48

def version
  puts "ESP #{ESP::VERSION}" # rubocop:disable Rails/Output
  exit(0)
end