From ecb0b5ac0a95eadc723d375ebb5d4f45af9f36b2 Mon Sep 17 00:00:00 2001 From: Tristan Zajonc Date: Tue, 4 Aug 2015 21:13:28 -0700 Subject: [PATCH] improve help by including parent command for subcommands --- command.go | 4 ++++ help.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/command.go b/command.go index 5b6cd66..d03b7e7 100644 --- a/command.go +++ b/command.go @@ -39,6 +39,9 @@ type Command struct { // Boolean to hide built-in help command HideHelp bool + // Name of parent command for help, defaults to app.Name and parent + // command.Name. + ParentName string commandNamePath []string } @@ -196,6 +199,7 @@ func (c Command) startApp(ctx *Context) error { var newCmds []Command for _, cc := range app.Commands { + cc.ParentName = app.Name cc.commandNamePath = []string{c.Name, cc.Name} newCmds = append(newCmds, cc) } diff --git a/help.go b/help.go index 0855eb6..ff739ff 100644 --- a/help.go +++ b/help.go @@ -38,10 +38,10 @@ COPYRIGHT: // cli.go uses text/template to render templates. You can // render custom help text by setting this variable. var CommandHelpTemplate = `NAME: - {{.FullName}} - {{.Usage}} + {{.ParentName}} {{.Name}} - {{.Usage}} USAGE: - command {{.FullName}}{{if .Flags}} [command options]{{end}} {{.ArgsUsage}}{{if .Description}} + {{.ParentName}} {{.Name}}{{if .Flags}} [command options]{{end}} {{.ArgsUsage}}{{if .Description}} DESCRIPTION: {{.Description}}{{end}}{{if .Flags}}