Merge pull request #86 from zenoss/upstream/feature/help-version-flags
Can now change these default flags in other applications
This commit is contained in:
commit
c05720b864
6
app.go
6
app.go
@ -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 {
|
||||||
@ -60,7 +60,7 @@ func (c Command) Run(ctx *Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if firstFlagIndex > -1 && !c.SkipFlagParsing{
|
if firstFlagIndex > -1 && !c.SkipFlagParsing {
|
||||||
args := ctx.Args()
|
args := ctx.Args()
|
||||||
regularArgs := args[1:firstFlagIndex]
|
regularArgs := args[1:firstFlagIndex]
|
||||||
flagArgs := args[firstFlagIndex:]
|
flagArgs := args[firstFlagIndex:]
|
||||||
|
6
flag.go
6
flag.go
@ -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…
Reference in New Issue
Block a user