From 7e355a723d928756d38acb2ea818d90e1ec967da Mon Sep 17 00:00:00 2001 From: Dave Copeland Date: Sun, 17 Mar 2013 13:05:12 -0400 Subject: [PATCH] omitted desc + default_command no longer crashes Seems if you omit the description for a comamnd, and then make that command the default command in a subcommand setup, we tried to plus nil, which doesn't work. Hopefully closes #131 --- .../help_modules/command_help_format.rb | 2 +- test/tc_help.rb | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/gli/commands/help_modules/command_help_format.rb b/lib/gli/commands/help_modules/command_help_format.rb index 5ec669e8..1845641a 100644 --- a/lib/gli/commands/help_modules/command_help_format.rb +++ b/lib/gli/commands/help_modules/command_help_format.rb @@ -103,7 +103,7 @@ def global_flags_and_switches def format_subcommands(command) commands_array = @sorter.call(command.commands_declaration_order).map { |cmd| if command.get_default_command == cmd.name - [cmd.names,cmd.description + " (default)"] + [cmd.names,String(cmd.description) + " (default)"] else [cmd.names,cmd.description] end diff --git a/test/tc_help.rb b/test/tc_help.rb index bfe95f9a..fe25a31d 100644 --- a/test/tc_help.rb +++ b/test/tc_help.rb @@ -151,6 +151,34 @@ class TestApp } end + test_that "omitting default_description doesn't blow up" do + Given { + app = TestApp.new + app.instance_eval do + command :top do |top| + top.command :list do |list| + list.action do |g,o,a| + end + end + + top.command :new do |new| + new.action do |g,o,a| + end + end + + top.default_command :list + end + end + @command = GLI::Commands::Help.new(app,@output,@error) + } + When { + @code = lambda { @command.execute({},{},['top']) } + } + Then { + assert_nothing_raised(&@code) + } + end + private def a_GLI_app(omit_options=false)