@@ -25,17 +25,19 @@ class WelcomeCommand < Cling::Command
2525 end
2626end
2727
28- command = GreetCommand .new
29- command.add_command WelcomeCommand .new
28+ command_with_subcommand = GreetCommand .new
29+ command_with_subcommand.add_command WelcomeCommand .new
30+
31+ command_without_subcommand = GreetCommand .new
3032formatter = Cling ::Formatter .new
3133
3234describe Cling ::Formatter do
3335 it " generates a help template" do
34- formatter.generate(command ).chomp.should eq <<-HELP
36+ formatter.generate(command_with_subcommand ).chomp.should eq <<-HELP
3537 Greets a person
3638
3739 Usage:
38- \t greet <arguments> [options]
40+ \t greet <command> < arguments> [options]
3941
4042 Commands:
4143 \t welcome sends a friendly welcome message
@@ -53,11 +55,11 @@ describe Cling::Formatter do
5355 it " generates with a custom delimiter" do
5456 formatter.options.option_delim = '+'
5557
56- formatter.generate(command ).chomp.should eq <<-HELP
58+ formatter.generate(command_with_subcommand ).chomp.should eq <<-HELP
5759 Greets a person
5860
5961 Usage:
60- \t greet <arguments> [options]
62+ \t greet <command> < arguments> [options]
6163
6264 Commands:
6365 \t welcome sends a friendly welcome message
@@ -74,27 +76,33 @@ describe Cling::Formatter do
7476
7577 it " generates a description section" do
7678 String .build do |io |
77- formatter.format_description(command , io)
79+ formatter.format_description(command_with_subcommand , io)
7880 end .should eq " Greets a person\n\n "
7981 end
8082
81- it " generates a usage section" do
83+ it " generates a usage section with subcommand" do
84+ String .build do |io |
85+ formatter.format_usage(command_with_subcommand, io)
86+ end .should eq " Usage:\n\t greet <command> <arguments> [options]\n\n "
87+ end
88+
89+ it " generates a usage section without subcommand" do
8290 String .build do |io |
83- formatter.format_usage(command , io)
91+ formatter.format_usage(command_without_subcommand , io)
8492 end .should eq " Usage:\n\t greet <arguments> [options]\n\n "
8593 end
8694
8795 it " generates an arguments section" do
8896 String .build do |io |
89- formatter.format_arguments(command , io)
97+ formatter.format_arguments(command_with_subcommand , io)
9098 end .should eq " Arguments:\n\t name the name of the person (required)\n\n "
9199 end
92100
93101 it " generates an options section" do
94102 formatter.options.option_delim = '-'
95103
96104 String .build do |io |
97- formatter.format_options(command , io)
105+ formatter.format_options(command_with_subcommand , io)
98106 end .chomp.should eq <<-HELP
99107 Options:
100108 \t -h, --help sends help information
0 commit comments