class ESP::CommandsTasks

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. @private

Constants

COMMAND_WHITELIST
HELP_MESSAGE

Attributes

argv[R]

Public Class Methods

new(argv) click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 23
def initialize(argv)
  @argv = argv
end

Public Instance Methods

add_external_account() click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 45
def add_external_account
  require_command!("add_external_account")
end
console() click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 38
def console
  require_command!("console")

  print_banner
  ESP::Console.new.start
end
help() click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 54
def help
  write_help_message
end
run_command!(command) click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 27
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
version() click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 49
def version
  puts "ESP #{ESP::VERSION}" # rubocop:disable Rails/Output
  exit(0)
end

Private Instance Methods

parse_command(command) click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 82
def parse_command(command)
  case command
  when '--version', '-v'
    'version'
  when '--help', '-h'
    'help'
  else
    command
  end
end
print_banner() click to toggle source
require_command!(command) click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 64
def require_command!(command)
  require_relative "./#{command}"
end
set_env!() click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 68
def set_env!
  ENV['ESP_ENV'] = argv.first if argv.first && argv.first[0] != '-'
end
shift_argv!() click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 60
def shift_argv!
  argv.shift if argv.first && argv.first[0] != '-'
end
write_error_message(command) click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 76
def write_error_message(command)
  puts "Error: Command '#{command}' not recognized" # rubocop:disable Rails/Output
  write_help_message
  exit(1)
end
write_help_message() click to toggle source
# File lib/esp/commands/commands_tasks.rb, line 72
def write_help_message
  puts HELP_MESSAGE # rubocop:disable Rails/Output
end