Class: SecureKeys::Validation::Console::Argument::Parser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/validation/console/arguments/parser.rb

Overview

Routes the ‘validate` subcommand to the appropriate sub-parser and action. The constructor reads the subcommand token from ARGV; execute then delegates to the matching sub-parser and runs the action.

Instance Method Summary collapse

Constructor Details

#initializeParser

Initialize the validate argument parser and capture the subcommand token



18
19
20
21
22
23
# File 'lib/validation/console/arguments/parser.rb', line 18

def initialize
  super('Usage: secure-keys validate [subcommand] [--options]')
  separator('')
  configure!
  @subcommand = ARGV.shift
end

Instance Method Details

#executevoid

This method returns an undefined value.

Dispatch to the correct sub-parser and action based on the subcommand



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/validation/console/arguments/parser.rb', line 27

def execute
  case @subcommand
  when 'scan'
    Scan::Parser.new
    Actions::Scan.new.run
  when nil, '--help', '-h'
    puts self
    exit(0)
  else
    Core::Console::Logger.error(message: "Unknown validate subcommand: '#{@subcommand}'")
    puts self
    exit(1)
  end
end