diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2012-12-24 00:26:43 -0800 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2012-12-24 00:26:43 -0800 |
commit | 5aa3b103e199c1c6f24bf782894ab51e8627520d (patch) | |
tree | eceebba0f795b40541dd9194c0c8e22cb63359ee | |
parent | 2e7165230be95906963b600216e0712edbc8e423 (diff) | |
parent | ad20e3b5b42210231e7aa6664582e02d46662246 (diff) | |
download | slop-5aa3b103e199c1c6f24bf782894ab51e8627520d.tar.gz |
Merge pull request #97 from kyrylo/help-output-fix
Don't always append global/default headers
-rw-r--r-- | lib/slop/commands.rb | 8 | ||||
-rw-r--r-- | test/commands_test.rb | 14 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/slop/commands.rb b/lib/slop/commands.rb index abaa913..0e3184b 100644 --- a/lib/slop/commands.rb +++ b/lib/slop/commands.rb @@ -157,8 +157,12 @@ class Slop defaults = commands.delete('default') globals = commands.delete('global') helps = commands.reject { |_, v| v.options.none? } - helps.merge!('Global options' => globals.to_s) if globals - helps.merge!('Other options' => defaults.to_s) if defaults + if globals && globals.options.any? + helps.merge!('Global options' => globals.to_s) + end + if defaults && defaults.options.any? + helps.merge!('Other options' => defaults.to_s) + end banner = @banner ? "#{@banner}\n" : "" banner + helps.map { |key, opts| " #{key}\n#{opts}" }.join("\n\n") end diff --git a/test/commands_test.rb b/test/commands_test.rb index 174dcf2..6721400 100644 --- a/test/commands_test.rb +++ b/test/commands_test.rb @@ -13,6 +13,16 @@ class CommandsTest < TestCase add_callback(:empty) { 'version 1' } end end + + @empty_commands = Slop::Commands.new do + default do + end + + global do + end + + on 'verbose' + end end test "it nests instances of Slop" do @@ -75,6 +85,10 @@ class CommandsTest < TestCase assert_kind_of Slop, @commands.global end + test "empty default/global blocks don't add their titles in the help output" do + assert_empty @empty_commands.to_s + end + test "parse does nothing when there's nothing to parse" do assert @commands.parse [] end |