Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
at-grandpa committed Dec 16, 2018
1 parent 185f338 commit d98ca65
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
69 changes: 48 additions & 21 deletions spec/clim/command/help_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SpecCommandNoSubCommands < Clim
desc "main command."
usage "main [sub_command] [arguments]"
option "-g WORDS", "--greeting=WORDS", type: String, desc: "Words of greetings.", default: "Hello"
option "-n NAME", "--name=NAME", type: Array(String), desc: "Target name.", default: ["Taro"]
option "-n NAME", type: Array(String), desc: "Target name.", default: ["Taro"], required: true
run do |opts, args|
end
end
Expand All @@ -51,7 +51,7 @@ describe Clim::Command::Help do
Options:
-g WORDS, --greeting=WORDS Words of greetings. [type:String] [default:\"Hello\"]
-n NAME, --name=NAME Target name. [type:Array(String)] [default:[\"Taro\"]]
-n NAME Target name. [type:Array(String)] [default:[\"Taro\"]] [required]
Sub Commands:
Expand All @@ -74,7 +74,7 @@ describe Clim::Command::Help do
Options:
-g WORDS, --greeting=WORDS Words of greetings. [type:String] [default:\"Hello\"]
-n NAME, --name=NAME Target name. [type:Array(String)] [default:[\"Taro\"]]
-n NAME Target name. [type:Array(String)] [default:[\"Taro\"]] [required]
OPTIONS
Expand All @@ -97,7 +97,7 @@ describe Clim::Command::Help do
help = Clim::Command::Help.new(SpecCommand.command)
help.parser.to_s.should eq <<-OPTIONS
-g WORDS, --greeting=WORDS Words of greetings. [type:String] [default:\"Hello\"]
-n NAME, --name=NAME Target name. [type:Array(String)] [default:[\"Taro\"]]
-n NAME Target name. [type:Array(String)] [default:[\"Taro\"]] [required]
OPTIONS
end
end
Expand Down Expand Up @@ -141,24 +141,51 @@ describe Clim::Command::Help do
end
end
describe "#options_info" do
it "returns option names." do
it "returns options info." do
help = Clim::Command::Help.new(SpecCommand.command)
help.options_info.should eq [
{
name: ["-g WORDS", "--greeting=WORDS"],
type: String,
desc: "Words of greetings.",
default: "Hello",
required: false,
},
{
name: ["-n NAME"],
type: Array(String),
desc: "Target name.",
default: ["Taro"],
required: true,
},
]
help.options_info.should eq ({
help: [
" -g WORDS, --greeting=WORDS Words of greetings. [type:String] [default:\"Hello\"]",
" -n NAME Target name. [type:Array(String)] [default:[\"Taro\"]] [required]",
],
info: [
{
name: ["-g WORDS", "--greeting=WORDS"],
type: String,
desc: "Words of greetings.",
default: "Hello",
required: false,
},
{
name: ["-n NAME"],
type: Array(String),
desc: "Target name.",
default: ["Taro"],
required: true,
},
],
})
end
end
describe "#sub_commands_info" do
it "returns sub commands info." do
help = Clim::Command::Help.new(SpecCommand.command)
help.sub_commands_info.should eq ({
help: [
" abc, def, ghi abc command.",
" abcdef, ghijkl, mnopqr abcdef command.",
],
info: [
{
name: ["abc", "def", "ghi"],
desc: "abc command.",
},
{
name: ["abcdef", "ghijkl", "mnopqr"],
desc: "abcdef command.",
},
],
})
end
end
end
18 changes: 17 additions & 1 deletion src/clim/command/help.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,23 @@ class Clim
end

def options_info
@command.options_info
{
help: @command.parser.to_s.split("\n"),
info: @command.options_info,
}
end

def sub_commands_info
sub_commands_info = @command.sub_commands.map do |cmd|
{
name: sub_commands_name_and_alias_name(cmd),
desc: cmd.desc,
}
end
{
help: sub_cmds_help_lines,
info: sub_commands_info,
}
end
end
end
Expand Down

0 comments on commit d98ca65

Please sign in to comment.