From 8532c31ab0d43ceac7c95956cd7405bbad74d549 Mon Sep 17 00:00:00 2001 From: tbpgr Date: Sat, 18 Feb 2017 05:38:54 +0900 Subject: [PATCH] Add dash if alias does not have dash --- 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 cb34d1ffd..d15fcee10 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -94,7 +94,7 @@ def usage(padding = 0) if aliases.empty? (" " * padding) << sample else - "#{aliases.join(', ')}, #{sample}" + "#{aliases.map{|e|e.to_s.sub(/^(?!\-)/, '-')}.join(', ')}, #{sample}" end end diff --git a/spec/parser/option_spec.rb b/spec/parser/option_spec.rb index 9e10972fb..6924782e8 100644 --- a/spec/parser/option_spec.rb +++ b/spec/parser/option_spec.rb @@ -226,9 +226,17 @@ def option(name, options = {}) expect(parse([:foo, "-f", "-b"], :required).usage).to eq("-f, -b, --foo=FOO") end + it "does not show the usage between brackets(include non-dash-prefixed aliases)" 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 + + it "does not negate the aliases(include non-dash-prefixed aliases)" do + expect(parse([:foo, "f", "-b"], :boolean).usage).to eq("-f, -b, [--foo], [--no-foo]") + end end end end