Class: Postqueue::CLI::OptionsParser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ OptionsParser

Returns a new instance of OptionsParser.



12
13
14
# File 'lib/postqueue/cli/options_parser.rb', line 12

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



10
11
12
# File 'lib/postqueue/cli/options_parser.rb', line 10

def argv
  @argv
end

Class Method Details

.parse_args(argv) ⇒ Object



6
7
8
# File 'lib/postqueue/cli/options_parser.rb', line 6

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

Instance Method Details

#parse_argsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/postqueue/cli/options_parser.rb', line 16

def parse_args
  require "optparse"
  options = OpenStruct.new
  options.sub_command = argv.shift || "stats"

  unless %w(stats peek enqueue run process).include?(options.sub_command)
    usage!
  end

  case options.sub_command
  when "enqueue"
    options.op = next_arg!
    options.entity_ids = next_arg!.split(",").map { |s| Integer(s) }
  end
  options
end