Class: Bane::ArgumentsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/bane/arguments_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(makeable_names) ⇒ ArgumentsParser

Returns a new instance of ArgumentsParser.



7
8
9
10
11
# File 'lib/bane/arguments_parser.rb', line 7

def initialize(makeable_names)
  @makeable_names = makeable_names
  @options = {host: default_host}
  @option_parser = init_option_parser
end

Instance Method Details

#parse(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bane/arguments_parser.rb', line 13

def parse(args)
  @option_parser.parse!(args)

  raise ConfigurationError, "Missing arguments" if args.empty?

  port = parse_port(args[0])
  behaviors = args.drop(1)
  ParsedArguments.new(port, @options[:host], behaviors)
rescue OptionParser::InvalidOption => io
  raise ConfigurationError, io.message
end

#usageObject



25
26
27
# File 'lib/bane/arguments_parser.rb', line 25

def usage
  @option_parser.help
end