Class: Serverkit::Command

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

Overview

This class is responsible for command line interface. An instance of this class builds an instance of Actions::Base class, then calls its ‘#call` method, and it exits with exit status 0 unless any error found. This class should be used only from bin/serverkit executable. If you need to use serverkit’s any feature from Ruby code, use a child of Actions::Base class instead because this class only focuses on command line interface.

Constant Summary collapse

LOG_LEVELS_TABLE =
{
  "" => Logger::INFO,
  "0" => Logger::DEBUG,
  "1" => Logger::INFO,
  "2" => Logger::WARN,
  "3" => Logger::ERROR,
  "4" => Logger::FATAL,
  "DEBUG" => Logger::DEBUG,
  "ERROR" => Logger::ERROR,
  "FATAL" => Logger::FATAL,
  "INFO" => Logger::INFO,
  "WARN" => Logger::WARN,
}

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command.

Parameters:

  • argv (Array<String>)


34
35
36
# File 'lib/serverkit/command.rb', line 34

def initialize(argv)
  @argv = argv
end

Instance Method Details

#callObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/serverkit/command.rb', line 38

def call
  setup
  case action_name
  when nil
    raise Errors::MissingActionNameArgumentError
  when "apply"
    apply
  when "check"
    check
  when "inspect"
    _inspect
  when "validate"
    validate
  else
    raise Errors::UnknownActionNameError, action_name
  end
rescue Errors::Base, Psych::SyntaxError, Slop::MissingArgumentError, Slop::MissingOptionError => exception
  abort "Error: #{exception}"
end