Merge pull request #86 from zenoss/upstream/feature/help-version-flags

Can now change these default flags in other applications
main
Jeremy Saenz 10 years ago
commit c05720b864

@ -74,8 +74,8 @@ func (a *App) Run(arguments []string) error {
if a.EnableBashCompletion { if a.EnableBashCompletion {
a.appendFlag(BashCompletionFlag) a.appendFlag(BashCompletionFlag)
} }
a.appendFlag(BoolFlag{"version, v", "print the version"}) a.appendFlag(VersionFlag)
a.appendFlag(BoolFlag{"help, h", "show help"}) a.appendFlag(HelpFlag)
// parse flags // parse flags
set := flagSet(a.Name, a.Flags) set := flagSet(a.Name, a.Flags)
@ -144,7 +144,7 @@ func (a *App) RunAsSubcommand(ctx *Context) error {
if a.EnableBashCompletion { if a.EnableBashCompletion {
a.appendFlag(BashCompletionFlag) a.appendFlag(BashCompletionFlag)
} }
a.appendFlag(BoolFlag{"help, h", "show help"}) a.appendFlag(HelpFlag)
// parse flags // parse flags
set := flagSet(a.Name, a.Flags) set := flagSet(a.Name, a.Flags)

@ -41,7 +41,7 @@ func (c Command) Run(ctx *Context) error {
// append help to flags // append help to flags
c.Flags = append( c.Flags = append(
c.Flags, c.Flags,
BoolFlag{"help, h", "show help"}, HelpFlag,
) )
if ctx.App.EnableBashCompletion { if ctx.App.EnableBashCompletion {

@ -10,6 +10,12 @@ import (
// This flag enables bash-completion for all commands and subcommands // This flag enables bash-completion for all commands and subcommands
var BashCompletionFlag = BoolFlag{"generate-bash-completion", ""} var BashCompletionFlag = BoolFlag{"generate-bash-completion", ""}
// This flag prints the version for the application
var VersionFlag = BoolFlag{"version, v", "print the version"}
// This flag prints the help for all commands and subcommands
var HelpFlag = BoolFlag{"help, h", "show help"}
// Flag is a common interface related to parsing flags in cli. // Flag is a common interface related to parsing flags in cli.
// For more advanced flag parsing techniques, it is recomended that // For more advanced flag parsing techniques, it is recomended that
// this interface be implemented. // this interface be implemented.

Loading…
Cancel
Save