diff --git a/lib/thor/base.rb b/lib/thor/base.rb index 6d7bae3d..c0fb960c 100644 --- a/lib/thor/base.rb +++ b/lib/thor/base.rb @@ -558,8 +558,7 @@ def print_options(shell, options, group_name = nil) return if options.empty? list = [] - padding = options.map { |o| o.aliases.size }.max.to_i * 4 - + padding = options.map { |o| o.aliases_for_usage.size }.max.to_i options.each do |option| next if option.hide item = [option.usage(padding)] diff --git a/lib/thor/parser/option.rb b/lib/thor/parser/option.rb index a7647bbe..3d389063 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -93,10 +93,14 @@ def usage(padding = 0) sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-") end + aliases_for_usage.ljust(padding) + sample + end + + def aliases_for_usage if aliases.empty? - (" " * padding) << sample + "" else - "#{aliases.join(', ')}, #{sample}" + "#{aliases.join(', ')}, " end end diff --git a/spec/base_spec.rb b/spec/base_spec.rb index e5a9561c..29ff7bd9 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -139,8 +139,9 @@ def hello end it "use padding in options that do not have aliases" do - expect(@content).to match(/^ -t, \[--third/) - expect(@content).to match(/^ \[--fourth/) + expect(@content).to match(/^ -t, \[--third/) + expect(@content).to match(/^ \[--fourth/) + expect(@content).to match(/^ y, r, \[--symbolic/) end it "allows extra options to be given" do