Skip to content

Commit

Permalink
Merge 1332764 into 6a21d8c
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Nov 5, 2014
2 parents 6a21d8c + 1332764 commit 18a0bd3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/trollop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class Parser
## for testing.)
attr_reader :specs

## A flag that determines whether or not to raise an error if the parser is passed one or more
## options that were not registered ahead of time. If 'true', then the parser will simply
## ignore options that it does not recognize.
attr_accessor :ignore_invalid_options

## Initializes the parser, and instance-evaluates any block given.
def initialize *a, &b
@version = nil
Expand Down Expand Up @@ -323,7 +328,10 @@ def parse cmdline=ARGV

sym = nil if arg =~ /--no-/ # explicitly invalidate --no-no- arguments

raise CommandlineError, "unknown argument '#{arg}'" unless sym
unless sym
next 0 if ignore_invalid_options
raise CommandlineError, "unknown argument '#{arg}'" unless sym
end

if given_args.include?(sym) && !@specs[sym][:multi]
raise CommandlineError, "option '#{arg}' specified multiple times"
Expand Down Expand Up @@ -408,6 +416,8 @@ def parse cmdline=ARGV
vals[sym] = vals[sym][0] # single option, with multiple parameters
end
# else: multiple options, with multiple parameters

opts[:callback].call(vals[sym]) if opts.has_key?(:callback)
end

## modify input in place with only those
Expand Down

0 comments on commit 18a0bd3

Please sign in to comment.