提交 c83a4488 编写于 作者: M Mislav Marohnić

Make `--help`/`--version` explicit aliases for `help`/`version`

Before, the argument parser would translate `--help` and `--version` to
their equivalents without the dashes. Now it's not the parser's
responsibility to do that anymore. Instead, wire them up as subcommand
aliases in the runner.
上级 a132ab2a
......@@ -17,7 +17,7 @@ var cmdHelp = &Command{
func init() {
cmdHelp.Run = runHelp
CmdRunner.Use(cmdHelp)
CmdRunner.Use(cmdHelp, "--help")
}
func runHelp(cmd *Command, args *Args) {
......
......@@ -54,8 +54,11 @@ func (r *Runner) All() map[string]*Command {
return r.commands
}
func (r *Runner) Use(command *Command) {
func (r *Runner) Use(command *Command, aliases ...string) {
r.commands[command.Name()] = command
if len(aliases) > 0 {
r.commands[aliases[0]] = command
}
}
func (r *Runner) Lookup(name string) *Command {
......
......@@ -19,7 +19,7 @@ var cmdVersion = &Command{
}
func init() {
CmdRunner.Use(cmdVersion)
CmdRunner.Use(cmdVersion, "--version")
}
func runVersion(cmd *Command, args *Args) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册