Made bash completion command optional; still need to update documentation

This commit is contained in:
Summer Mousa
2014-04-12 08:32:53 -05:00
parent 0b29bee364
commit 3a10545f91
4 changed files with 38 additions and 16 deletions

23
help.go
View File

@@ -60,10 +60,21 @@ var helpCommand = Command{
// Prints help for the App
var HelpPrinter = printHelp
func ShowAppHelp(c *Context) {
HelpPrinter(AppHelpTemplate, c.App)
}
// Prints the list of subcommands as the default app completion method
func DefaultAppComplete(c *Context) {
for _, command := range c.App.Commands {
fmt.Println(command.Name)
if command.ShortName != "" {
fmt.Println(command.ShortName)
}
}
}
// Prints help for the given command
func ShowCommandHelp(c *Context, command string) {
for _, c := range c.App.Commands {
@@ -83,11 +94,9 @@ func ShowVersion(c *Context) {
// Prints the lists of commands within a given context
func ShowCompletions(c *Context) {
for _, command := range c.App.Commands {
fmt.Println(command.Name)
if command.ShortName != "" {
fmt.Println(command.ShortName)
}
a := c.App
if a != nil && a.BashComplete != nil {
a.BashComplete(c)
}
}
@@ -137,7 +146,7 @@ func checkCommandHelp(c *Context, name string) bool {
}
func checkCompletions(c *Context) bool {
if c.GlobalBool("generate-bash-completion") {
if c.GlobalBool(BashCompletionFlag.Name) && c.App.EnableBashCompletion {
ShowCompletions(c)
return true
}
@@ -146,7 +155,7 @@ func checkCompletions(c *Context) bool {
}
func checkCommandCompletions(c *Context, name string) bool {
if c.Bool("generate-bash-completion") {
if c.Bool(BashCompletionFlag.Name) && c.App.EnableBashCompletion {
ShowCommandCompletions(c, name)
return true
}