Class: Mammoth::CLI

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

Overview

Small command dispatcher for Mammoth’s operator-facing CLI.

Constant Summary collapse

USAGE =
[
  "Usage:",
  "  mammoth version",
  "  mammoth validate CONFIG",
  "  mammoth bootstrap CONFIG",
  "  mammoth status CONFIG",
  "  mammoth start CONFIG",
  "  mammoth deliver-sample CONFIG EVENT_JSON"
].join("\n")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • argv (Array<String>)

    command line arguments



29
30
31
# File 'lib/mammoth/cli.rb', line 29

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



26
27
28
# File 'lib/mammoth/cli.rb', line 26

def argv
  @argv
end

Class Method Details

.call(argv) ⇒ Integer

Run the CLI.

Parameters:

  • argv (Array<String>)

    command line arguments

Returns:

  • (Integer)

    process status code



22
23
24
# File 'lib/mammoth/cli.rb', line 22

def self.call(argv)
  new(argv).call
end

Instance Method Details

#callInteger

Dispatch the requested command.

Returns:

  • (Integer)

    process status code



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mammoth/cli.rb', line 36

def call
  case command
  when "version" then version
  when "validate" then validate
  when "bootstrap" then bootstrap
  when "status" then status
  when "start" then start
  when "deliver-sample" then deliver_sample
  else
    warn USAGE
    1
  end
rescue Mammoth::Error => e
  warn e.message
  1
end