From ca7b2b6b5c49af1a8aa9b9d40d58eb4a634960cd Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Tue, 7 Mar 2017 15:26:57 +0000 Subject: [PATCH] Fix double negatives on bool opts with underscores Because: * https://github.com/erikhuda/thor/pull/460 (released in `0.19.2`) introduced a change that prevents double negative options (`--no-no-foo`) for already negative boolean options (`--no-foo`). * That change checks if the option name string starts with 'no-', before it's `dasherized`, therefore negative options defined with underscores (`:no_foo`) still generate a double negative `--no-no-foo` option. This change: * Adds a test for, and fixes the double negative boolean options defined with underscores. --- lib/thor/parser/option.rb | 2 +- spec/parser/option_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/thor/parser/option.rb b/lib/thor/parser/option.rb index cb34d1ffd..4ced3fa8a 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -88,7 +88,7 @@ def usage(padding = 0) sample = "[#{sample}]" unless required? if boolean? - sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-") + sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-", "no_") end if aliases.empty? diff --git a/spec/parser/option_spec.rb b/spec/parser/option_spec.rb index 9e10972fb..e3b03c456 100644 --- a/spec/parser/option_spec.rb +++ b/spec/parser/option_spec.rb @@ -201,6 +201,7 @@ def option(name, options = {}) it "does not document a negative option for a negative boolean" do expect(parse(:'no-foo', :boolean).usage).not_to include("[--no-no-foo]") + 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