Class: Kdep::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/kdep/cli.rb

Constant Summary collapse

COMMANDS =
{
  "render" => Commands::Render,
  "init"   => Commands::Init,
  "eject"  => Commands::Eject,
  "apply"  => Commands::Apply,
  "diff"   => Commands::Diff,
  "status" => Commands::Status,
  "build"  => Commands::Build,
  "push"   => Commands::Push,
  "bump"   => Commands::Bump,
  "log"    => Commands::Log,
  "sh"      => Commands::Sh,
  "secrets" => Commands::Secrets,
  "restart" => Commands::Restart,
  "scale"   => Commands::Scale,
  "migrate" => Commands::Migrate,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



23
24
25
26
# File 'lib/kdep/cli.rb', line 23

def initialize(argv)
  @argv = argv.dup
  @global_options = {}
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kdep/cli.rb', line 28

def run
  global_parser.order!(@argv, into: @global_options)
  command_name = @argv.shift

  if command_name.nil?
    puts global_parser
    exit 0
  end

  unless COMMANDS.key?(command_name)
    $stderr.puts "Unknown command: #{command_name}"
    puts global_parser
    exit 1
  end

  command_class = COMMANDS[command_name]
  command_options = {}
  command_class.option_parser.parse!(@argv, into: command_options)
  command_class.new(
    global_options: @global_options,
    command_options: command_options,
    args: @argv
  ).execute
end