diff options
Diffstat (limited to 'lib/bundler/vendor/thor/parser')
-rw-r--r-- | lib/bundler/vendor/thor/parser/arguments.rb | 4 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/parser/option.rb | 5 | ||||
-rw-r--r-- | lib/bundler/vendor/thor/parser/options.rb | 20 |
3 files changed, 20 insertions, 9 deletions
diff --git a/lib/bundler/vendor/thor/parser/arguments.rb b/lib/bundler/vendor/thor/parser/arguments.rb index 888ef692..12db2b23 100644 --- a/lib/bundler/vendor/thor/parser/arguments.rb +++ b/lib/bundler/vendor/thor/parser/arguments.rb @@ -49,6 +49,10 @@ class Thor @assigns end + def remaining + @pile + end + private def no_or_skip?(arg) diff --git a/lib/bundler/vendor/thor/parser/option.rb b/lib/bundler/vendor/thor/parser/option.rb index c8f20b13..26da9d6b 100644 --- a/lib/bundler/vendor/thor/parser/option.rb +++ b/lib/bundler/vendor/thor/parser/option.rb @@ -1,14 +1,15 @@ class Thor class Option < Argument #:nodoc: - attr_reader :aliases, :group, :lazy_default + attr_reader :aliases, :group, :lazy_default, :hide VALID_TYPES = [:boolean, :numeric, :hash, :array, :string] - def initialize(name, description=nil, required=nil, type=nil, default=nil, banner=nil, lazy_default=nil, group=nil, aliases=nil) + def initialize(name, description=nil, required=nil, type=nil, default=nil, banner=nil, lazy_default=nil, group=nil, aliases=nil, hide=nil) super(name, description, required, type, default, banner) @lazy_default = lazy_default @group = group.to_s.capitalize if group @aliases = [*aliases].compact + @hide = hide end # This parse quick options given as method_options. It makes several diff --git a/lib/bundler/vendor/thor/parser/options.rb b/lib/bundler/vendor/thor/parser/options.rb index 4a241a47..81b671df 100644 --- a/lib/bundler/vendor/thor/parser/options.rb +++ b/lib/bundler/vendor/thor/parser/options.rb @@ -35,7 +35,7 @@ class Thor @non_assigned_required.delete(hash_options[key]) end - @shorts, @switches, @unknown = {}, {}, [] + @shorts, @switches, @extra = {}, {}, [] options.each do |option| @switches[option.switch_name] = option @@ -46,14 +46,19 @@ class Thor end end + def remaining + @extra + end + def parse(args) @pile = args.dup while peek match, is_switch = current_is_switch? + shifted = shift if is_switch - case shift + case shifted when SHORT_SQ_RE unshift($1.split('').map { |f| "-#{f}" }) next @@ -68,9 +73,10 @@ class Thor option = switch_option(switch) @assigns[option.human_name] = parse_peek(switch, option) elsif match - @unknown << shift + @extra << shifted + @extra << shift while peek && peek !~ /^-/ else - shift + @extra << shifted end end @@ -82,9 +88,9 @@ class Thor end def check_unknown! - unless ARGV.include?("exec") || ARGV.include?("config") - raise UnknownArgumentError, "Unknown switches '#{@unknown.join(', ')}'" unless @unknown.empty? - end + # an unknown option starts with - or -- and has no more --'s afterward. + unknown = @extra.select { |str| str =~ /^--?(?:(?!--).)*$/ } + raise UnknownArgumentError, "Unknown switches '#{unknown.join(', ')}'" unless unknown.empty? end protected |