Class: ECSHelper::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_helper/command.rb

Defined Under Namespace

Classes: Base, BuildAndPush, CheckExec, Deploy, ECRLogin, Exec, ExportEnvSecrets, ExportImages, RunCommand

Constant Summary collapse

CMD_MAPPING =
{
  "build_and_push" => BuildAndPush,
  "deploy" => Deploy,
  "export_images" => ExportImages,
  "ecr_login" => ECRLogin,
  "run_command" => RunCommand,
  "export_env_secrets" => ExportEnvSecrets,
  "exec" => Exec,
  "check_exec" => CheckExec,
}
AVAILABLE_COMMANDS =
CMD_MAPPING.keys

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(helper) ⇒ Command

Returns a new instance of Command.



27
28
29
30
31
# File 'lib/ecs_helper/command.rb', line 27

def initialize(helper)
  @helper = helper
  @type = ARGV.shift
  @command = klass.new(helper)
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



25
26
27
# File 'lib/ecs_helper/command.rb', line 25

def command
  @command
end

#helperObject

Returns the value of attribute helper.



25
26
27
# File 'lib/ecs_helper/command.rb', line 25

def helper
  @helper
end

#typeObject

Returns the value of attribute type.



25
26
27
# File 'lib/ecs_helper/command.rb', line 25

def type
  @type
end

Instance Method Details

#klassObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/ecs_helper/command.rb', line 33

def klass
  CMD_MAPPING[type] || begin
    messages = [
      "Command not found".light_white,
      "Available commands are #{AVAILABLE_COMMANDS}".light_white,
      global_option_parser
    ]
    raise ECSHelper::Error::CommandNotFound.new(messages)
  end
end

#optionsObject



44
45
46
# File 'lib/ecs_helper/command.rb', line 44

def options
  command.options
end

#runObject



48
49
50
51
52
53
# File 'lib/ecs_helper/command.rb', line 48

def run
  command.validate
  result = command.run
  puts result if command.printable?
  result
end