Module: Sinatras::Command::Options

Defined in:
lib/sinatras/command/options.rb

Class Method Summary collapse

Class Method Details

.parse!(argv) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sinatras/command/options.rb', line 8

def self.parse!(argv)
  options = {}

  sub_command_parsers = create_sub_command_parsers(options)
  command_parser = create_command_parser


  begin
    command_parser.order!(argv)

    options[:command] = argv.shift

    sub_command_parsers[options[:command]].parse!(argv)

    if options[:command] == 'new'
      raise ArgumentError, "#{options[:command]} Appname not found." if argv.empty?
      options[:appname] = String(argv.first)
    end

  rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
    abort e.message
  end

  options
end