Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: urfave/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.23.6
Choose a base ref
...
head repository: urfave/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.23.7
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 7, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    kzaher Krunoslav Zaher
    Copy the full SHA
    badc19f View commit details
  2. Fix docs issue

    dearchap committed Dec 7, 2022
    Copy the full SHA
    659672b View commit details

Commits on Dec 10, 2022

  1. Merge pull request #1618 from dearchap/issue_1617

    Fix:(issue_1617) Fix Bash completion for subcommands
    dearchap authored Dec 10, 2022
    Copy the full SHA
    a6194b9 View commit details
Showing with 11 additions and 20 deletions.
  1. +5 −5 command.go
  2. +6 −15 help.go
10 changes: 5 additions & 5 deletions command.go
Original file line number Diff line number Diff line change
@@ -136,6 +136,10 @@ func (c *Command) setup(ctx *Context) {
newCmds = append(newCmds, scmd)
}
c.Subcommands = newCmds

if c.BashComplete == nil {
c.BashComplete = DefaultCompleteWithFlags(c)
}
}

func (c *Command) Run(cCtx *Context, arguments ...string) (err error) {
@@ -148,11 +152,7 @@ func (c *Command) Run(cCtx *Context, arguments ...string) (err error) {
set, err := c.parseFlags(&a, cCtx.shellComplete)
cCtx.flagSet = set

if c.isRoot {
if checkCompletions(cCtx) {
return nil
}
} else if checkCommandCompletions(cCtx, c.Name) {
if checkCompletions(cCtx) {
return nil
}

21 changes: 6 additions & 15 deletions help.go
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context) {
return
}

printCommandSuggestions(cCtx.App.Commands, cCtx.App.Writer)
printCommandSuggestions(cCtx.Command.Subcommands, cCtx.App.Writer)
}
}

@@ -308,15 +308,15 @@ func printVersion(cCtx *Context) {

// ShowCompletions prints the lists of commands within a given context
func ShowCompletions(cCtx *Context) {
a := cCtx.App
if a != nil && a.BashComplete != nil {
a.BashComplete(cCtx)
c := cCtx.Command
if c != nil && c.BashComplete != nil {
c.BashComplete(cCtx)
}
}

// ShowCommandCompletions prints the custom completions for a given command
func ShowCommandCompletions(ctx *Context, command string) {
c := ctx.App.Command(command)
c := ctx.Command.Command(command)
if c != nil {
if c.BashComplete != nil {
c.BashComplete(ctx)
@@ -453,7 +453,7 @@ func checkCompletions(cCtx *Context) bool {

if args := cCtx.Args(); args.Present() {
name := args.First()
if cmd := cCtx.App.Command(name); cmd != nil {
if cmd := cCtx.Command.Command(name); cmd != nil {
// let the command handle the completion
return false
}
@@ -463,15 +463,6 @@ func checkCompletions(cCtx *Context) bool {
return true
}

func checkCommandCompletions(c *Context, name string) bool {
if !c.shellComplete {
return false
}

ShowCommandCompletions(c, name)
return true
}

func subtract(a, b int) int {
return a - b
}