Refactoring names from bash to shell
The refactoring is required since completion is also supported for zsh shell. Refactoring details: - flag generate-bash-completion -> generate-completion - var EnableBashCompletion -> EnableShellCompletion - var BashComplete -> ShellComplete - var BashCompletionFlag -> GenerateCompletionFlag - type BashCompleteFunc -> ShellCompleteFunc
This commit is contained in:
29
app.go
29
app.go
@@ -29,16 +29,16 @@ type App struct {
|
||||
Commands []*Command
|
||||
// List of flags to parse
|
||||
Flags []Flag
|
||||
// Boolean to enable bash completion commands
|
||||
EnableBashCompletion bool
|
||||
// Boolean to enable shell completion commands
|
||||
EnableShellCompletion bool
|
||||
// Boolean to hide built-in help command
|
||||
HideHelp bool
|
||||
// Boolean to hide built-in version flag and the VERSION section of help
|
||||
HideVersion bool
|
||||
// Categories contains the categorized commands and is populated on app startup
|
||||
Categories CommandCategories
|
||||
// An action to execute when the bash-completion flag is set
|
||||
BashComplete BashCompleteFunc
|
||||
// An action to execute when the shell completion flag is set
|
||||
ShellComplete ShellCompleteFunc
|
||||
// An action to execute before any subcommands are run, but after the context is ready
|
||||
// If a non-nil error is returned, no subcommands are run
|
||||
Before BeforeFunc
|
||||
@@ -103,8 +103,8 @@ func (a *App) Setup() {
|
||||
a.Version = "0.0.0"
|
||||
}
|
||||
|
||||
if a.BashComplete == nil {
|
||||
a.BashComplete = DefaultAppComplete
|
||||
if a.ShellComplete == nil {
|
||||
a.ShellComplete = DefaultAppComplete
|
||||
}
|
||||
|
||||
if a.Action == nil {
|
||||
@@ -136,8 +136,8 @@ func (a *App) Setup() {
|
||||
}
|
||||
}
|
||||
|
||||
if a.EnableBashCompletion {
|
||||
a.appendFlag(BashCompletionFlag)
|
||||
if a.EnableShellCompletion {
|
||||
a.appendFlag(GenerateCompletionFlag)
|
||||
a.appendFlag(InitCompletionFlag)
|
||||
}
|
||||
|
||||
@@ -177,9 +177,12 @@ func (a *App) Run(arguments []string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var done bool
|
||||
if done, err = checkInitCompletion(context); done {
|
||||
return nil
|
||||
if done, cerr := checkInitCompletion(context); done {
|
||||
if cerr != nil {
|
||||
err = cerr
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -266,8 +269,8 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
||||
a.Commands = newCmds
|
||||
|
||||
// append flags
|
||||
if a.EnableBashCompletion {
|
||||
a.appendFlag(BashCompletionFlag)
|
||||
if a.EnableShellCompletion {
|
||||
a.appendFlag(GenerateCompletionFlag)
|
||||
}
|
||||
|
||||
// parse flags
|
||||
|
Reference in New Issue
Block a user