From d65fef7e6d41c4204e6a68a33e628c3e0c498397 Mon Sep 17 00:00:00 2001 From: Aurelien Derouineau Date: Tue, 2 Dec 2014 12:27:09 -0500 Subject: [PATCH] Do not generate a negative option (--no-no-foo) for already negative boolean options (--no-foo) --- lib/thor/parser/option.rb | 2 +- spec/parser/option_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/thor/parser/option.rb b/lib/thor/parser/option.rb index 21456f87a..8d4e9d444 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -86,7 +86,7 @@ def usage(padding = 0) sample = "[#{sample}]" unless required? if boolean? - sample << ", [#{dasherize("no-" + human_name)}]" unless name == "force" + sample << ", [#{dasherize("no-" + human_name)}]" unless name == "force" or name.start_with?("no-") end if aliases.empty? diff --git a/spec/parser/option_spec.rb b/spec/parser/option_spec.rb index 430393d94..ff81a767a 100644 --- a/spec/parser/option_spec.rb +++ b/spec/parser/option_spec.rb @@ -189,6 +189,14 @@ def option(name, options = {}) 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]") + end + it "uses banner when supplied" do expect(option(:foo, :required => false, :type => :string, :banner => "BAR").usage).to eq("[--foo=BAR]") end