From 179beaa692ae584d0e2cfc265ba067f35e047d2f Mon Sep 17 00:00:00 2001 From: at-grandpa Date: Mon, 2 Jul 2018 09:11:25 +0900 Subject: [PATCH] ... --- .../compile_time_error_spec.cr | 18 +++++++++- .../files/main_command_with_custom_help.cr | 34 +++++++++++++++++++ .../files/sub_command_with_custom_help.cr | 5 ++- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 spec/clim/compile_time_error_spec/files/main_command_with_custom_help.cr diff --git a/spec/clim/compile_time_error_spec/compile_time_error_spec.cr b/spec/clim/compile_time_error_spec/compile_time_error_spec.cr index 117e076a..2fe62697 100644 --- a/spec/clim/compile_time_error_spec/compile_time_error_spec.cr +++ b/spec/clim/compile_time_error_spec/compile_time_error_spec.cr @@ -85,10 +85,26 @@ describe "Compile time spec, " do `crystal run spec/clim/compile_time_error_spec/files/sub_command_with_custom_help.cr --no-color 2>&1`.should eq <<-ERROR Error in spec/clim/compile_time_error_spec/files/sub_command_with_custom_help.cr:8: Can not be declared 'custom_help' as sub command. - custom_help do |desc, usage, options_help| + custom_help do |desc, usage, options_help, sub_commands| ^~~~~~~~~~~ ERROR end + it "display sub_command help when main command with custom_help." do + `crystal run spec/clim/compile_time_error_spec/files/main_command_with_custom_help.cr --no-color -- sub_command --help`.should eq <<-DISPLAY + + command description: sub_comand. + command usage: sub_command [options] [arguments] + + options: + -n NUM Number. [type:Int32] [default:0] + --help Show this help. + + sub_commands: + sub_sub_command sub_sub_comand description. + + + DISPLAY + end end diff --git a/spec/clim/compile_time_error_spec/files/main_command_with_custom_help.cr b/spec/clim/compile_time_error_spec/files/main_command_with_custom_help.cr new file mode 100644 index 00000000..b05e2ed1 --- /dev/null +++ b/spec/clim/compile_time_error_spec/files/main_command_with_custom_help.cr @@ -0,0 +1,34 @@ +require "./../../../../src/clim" + +class MyCli < Clim + main_command do + custom_help do |desc, usage, options_help, sub_commands| + <<-MY_HELP + command description: \#{desc} + command usage: \#{usage} + + options: + \#{options_help} + + sub_commands: + \#{sub_commands} + MY_HELP + end + run do |opts, args| + end + sub_command "sub_command" do + desc "sub_comand." + option "-n NUM", type: Int32, desc: "Number.", default: 0 + run do |opts, args| + end + sub_command "sub_sub_command" do + desc "sub_sub_comand description." + option "-p PASSWORD", type: String, desc: "Password.", required: true + run do |opts, args| + end + end + end + end +end + +MyCli.start(ARGV) diff --git a/spec/clim/compile_time_error_spec/files/sub_command_with_custom_help.cr b/spec/clim/compile_time_error_spec/files/sub_command_with_custom_help.cr index b2ba5cc9..c85b9a0e 100644 --- a/spec/clim/compile_time_error_spec/files/sub_command_with_custom_help.cr +++ b/spec/clim/compile_time_error_spec/files/sub_command_with_custom_help.cr @@ -5,13 +5,16 @@ class MyCli < Clim run do |opts, args| end sub_command "sub_command" do - custom_help do |desc, usage, options_help| + custom_help do |desc, usage, options_help, sub_commands| <<-MY_HELP command description: \#{desc} command usage: \#{usage} options: \#{options_help} + + sub_commands: + \#{sub_commands} MY_HELP end run do |opts, args|