Class: YamlSmith::CLI

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

Overview

Dispatches command-line arguments to a YAML Smith command.

Constant Summary collapse

COMMANDS =
{
  'add' => AddKey,
  'set' => SetKey,
  'delete' => DeleteKey
}.freeze
USAGE =
'Usage: yaml-smith COMMAND FILE KEY [VALUE]'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ CLI

Returns a new instance of CLI.



19
20
21
# File 'lib/yaml_smith/cli.rb', line 19

def initialize(arguments)
  @arguments = arguments
end

Class Method Details

.call(arguments) ⇒ Object



15
16
17
# File 'lib/yaml_smith/cli.rb', line 15

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

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
# File 'lib/yaml_smith/cli.rb', line 23

def call
  command = COMMANDS[@arguments.first]
  return usage unless valid_arguments?(command)

  command.call(*command_arguments)
rescue Error => e
  warn e.message
  1
end