Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
at-grandpa committed Jul 2, 2018
1 parent c12e0a9 commit 179beaa
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
18 changes: 17 additions & 1 deletion spec/clim/compile_time_error_spec/compile_time_error_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 179beaa

Please sign in to comment.