Class: Bookbinder::CommandValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/bookbinder/command_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(usage_messenger, commands, usage_text) ⇒ CommandValidator

Returns a new instance of CommandValidator.



5
6
7
8
9
# File 'lib/bookbinder/command_validator.rb', line 5

def initialize(usage_messenger, commands, usage_text)
  @usage_messenger = usage_messenger
  @commands = commands
  @usage_text = usage_text
end

Instance Method Details

#validate!(command_name) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/bookbinder/command_validator.rb', line 11

def validate! command_name
  known_command_names = commands.map(&:command_name)
  command_type = "#{command_name}".match(/^--/) ? 'flag' : 'command'
  if !known_command_names.include?(command_name)
    raise CliError::UnknownCommand.new "Unrecognized #{command_type} '#{command_name}'\n" + usage_text
  end
end