From bdd895825118637596be6aecb8a270025c7f732b Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Fri, 30 Jan 2015 02:38:02 -0500 Subject: [PATCH 1/2] remove automatic generation of --no-* flag for booleans --- lib/thor/parser/option.rb | 4 ---- spec/parser/option_spec.rb | 22 +--------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/lib/thor/parser/option.rb b/lib/thor/parser/option.rb index 8d4e9d444..4eb15928d 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -85,10 +85,6 @@ def usage(padding = 0) sample = "[#{sample}]" unless required? - if boolean? - sample << ", [#{dasherize("no-" + human_name)}]" unless name == "force" or name.start_with?("no-") - end - if aliases.empty? (" " * padding) << sample else diff --git a/spec/parser/option_spec.rb b/spec/parser/option_spec.rb index ff81a767a..5cc56691a 100644 --- a/spec/parser/option_spec.rb +++ b/spec/parser/option_spec.rb @@ -178,23 +178,7 @@ def option(name, options = {}) end it "returns usage for boolean types" do - expect(parse(:foo, :boolean).usage).to eq("[--foo], [--no-foo]") - end - - it "does not use padding when no aliases are given" do - expect(parse(:foo, :boolean).usage).to eq("[--foo], [--no-foo]") - end - - it "documents a negative option when boolean" do - expect(parse(:foo, :boolean).usage).to include("[--no-foo]") - end - - it "does not document a negative option for a negative boolean" do - expect(parse(:'no-foo', :boolean).usage).not_to include("[--no-no-foo]") - end - - it "documents a negative option for a positive boolean starting with 'no'" do - expect(parse(:'nougat', :boolean).usage).to include("[--no-nougat]") + expect(parse(:foo, :boolean).usage).to eq("[--foo]") end it "uses banner when supplied" do @@ -215,10 +199,6 @@ def option(name, options = {}) it "does not show the usage between brackets" do expect(parse([:foo, "-f", "-b"], :required).usage).to eq("-f, -b, --foo=FOO") end - - it "does not negate the aliases" do - expect(parse([:foo, "-f", "-b"], :boolean).usage).to eq("-f, -b, [--foo], [--no-foo]") - end end end end From b608d52ac2abe53ebe0db7e8cae63eba0c4fadb5 Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Fri, 30 Jan 2015 03:06:11 -0500 Subject: [PATCH 2/2] remove special handling of inverse boolean flags --- lib/thor/parser/arguments.rb | 20 +++++--------------- lib/thor/parser/options.rb | 12 +++--------- spec/group_spec.rb | 8 -------- spec/parser/options_spec.rb | 8 -------- 4 files changed, 8 insertions(+), 40 deletions(-) diff --git a/lib/thor/parser/arguments.rb b/lib/thor/parser/arguments.rb index 558e763b2..23539bdea 100644 --- a/lib/thor/parser/arguments.rb +++ b/lib/thor/parser/arguments.rb @@ -55,11 +55,6 @@ def remaining # rubocop:disable TrivialAccessors private - def no_or_skip?(arg) - arg =~ /^--(no|skip)-([-\w]+)$/ - $2 - end - def last? @pile.empty? end @@ -143,21 +138,16 @@ def parse_numeric(name) # Parse string: # for --string-arg, just return the current value in the pile - # for --no-string-arg, nil # Check if the peek is included in enum if enum is provided. Otherwise raises an error. # def parse_string(name) - if no_or_skip?(name) - nil - else - value = shift - if @switches.is_a?(Hash) && switch = @switches[name] # rubocop:disable AssignmentInCondition - if switch.enum && !switch.enum.include?(value) - fail MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}" - end + value = shift + if @switches.is_a?(Hash) && switch = @switches[name] # rubocop:disable AssignmentInCondition + if switch.enum && !switch.enum.include?(value) + fail MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}" end - value end + value end # Raises an error if @non_assigned_required array is not empty. diff --git a/lib/thor/parser/options.rb b/lib/thor/parser/options.rb index 6cfba1160..bece7a8ce 100644 --- a/lib/thor/parser/options.rb +++ b/lib/thor/parser/options.rb @@ -157,11 +157,7 @@ def switch?(arg) end def switch_option(arg) - if match = no_or_skip?(arg) # rubocop:disable AssignmentInCondition - @switches[arg] || @switches["--#{match}"] - else - @switches[arg] - end + @switches[arg] end # Check if the given argument is actually a shortcut. @@ -175,7 +171,7 @@ def parsing_options? @parsing_options end - # Parse boolean values which can be given as --foo=true, --foo or --no-foo. + # Parse boolean values which can be given as --foo=true or --foo. # def parse_boolean(switch) if current_is_value? @@ -189,7 +185,7 @@ def parse_boolean(switch) true end else - @switches.key?(switch) || !no_or_skip?(switch) + @switches.key?(switch) end end @@ -199,8 +195,6 @@ def parse_peek(switch, option) if parsing_options? && (current_is_switch_formatted? || last?) if option.boolean? # No problem for boolean types - elsif no_or_skip?(switch) - return nil # User set value to nil elsif option.string? && !option.required? # Return the default if there is one, else the human name return option.lazy_default || option.default || option.human_name diff --git a/spec/group_spec.rb b/spec/group_spec.rb index 823318f49..ff56260a7 100644 --- a/spec/group_spec.rb +++ b/spec/group_spec.rb @@ -116,10 +116,6 @@ expect(@content).to match(/1\n2\n3\n4\n5\n/) end - it "does not invoke if the option is nil" do - expect(capture(:stdout) { G.start(%w[--skip-invoked]) }).not_to match(/invoke/) - end - it "prints a message if invocation cannot be found" do content = capture(:stdout) { G.start(%w[--invoked unknown]) } expect(content).to match(/error unknown \[not found\]/) @@ -161,10 +157,6 @@ expect(@content).to match(/1\n2\n3\n4\n5\n/) end - it "does not invoke if the option is false" do - expect(capture(:stdout) { H.start(%w[--no-defined]) }).not_to match(/invoke/) - end - it "shows invocation information to the user" do expect(@content).to match(/invoke defined/) end diff --git a/spec/parser/options_spec.rb b/spec/parser/options_spec.rb index 9a6a21d24..2ca752239 100644 --- a/spec/parser/options_spec.rb +++ b/spec/parser/options_spec.rb @@ -128,7 +128,6 @@ def remaining it "accepts underscores in commandline args hash for boolean" do create :foo_bar => :boolean expect(parse("--foo_bar")["foo_bar"]).to eq(true) - expect(parse("--no_foo_bar")["foo_bar"]).to eq(false) end it "accepts underscores in commandline args hash for strings" do @@ -264,11 +263,6 @@ def remaining expect(parse("--foo_bar=http://example.com/under_score/")["foo_bar"]).to eq("http://example.com/under_score/") end - it "accepts a --no-switch format" do - create "--foo" => "bar" - expect(parse("--no-foo")["foo"]).to be nil - end - it "does not consume an argument for --no-switch format" do create "--cheese" => :string expect(parse("burger", "--no-cheese", "fries")["cheese"]).to be nil @@ -337,8 +331,6 @@ def remaining it "accepts inputs in the human name format" do create :foo_bar => :boolean expect(parse("--foo-bar")["foo_bar"]).to eq(true) - expect(parse("--no-foo-bar")["foo_bar"]).to eq(false) - expect(parse("--skip-foo-bar")["foo_bar"]).to eq(false) end it "doesn't eat the next part of the param" do