My urfave/cli version is
v3 (a9261cf)
Checklist
Dependency Management
- My project is using go modules.
Describe the bug
Shell completion does not show flag suggestions when the user types --<TAB> or --partial<TAB>.
To reproduce
- Create a CLI app with shell completion enabled and some flags
- Source the shell completion script
- Type
myapp --<TAB> or myapp --partial<TAB>
package main
import (
"context"
"os"
"github.com/urfave/cli/v3"
)
func main() {
cmd := &cli.Command{
Name: "myapp",
EnableShellCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{Name: "config"},
&cli.BoolFlag{Name: "verbose"},
},
Action: func(ctx context.Context, c *cli.Command) error {
return nil
},
}
cmd.Run(context.Background(), os.Args)
}
Observed behavior
myapp --<TAB> produces no completions
myapp --prefix<TAB> produces no completions
myapp -<TAB> appends another - and produces flag completions (correct)
Expected behavior
myapp --<TAB> should show all available flags (--config, --verbose, --help)
myapp --prefix<TAB> should show all matching flags
Additional context
The bug has four root causes:
checkShellCompleteFlag() disables completion mode when -- appears anywhere in arguments, but -- is the token being completed
DefaultCompleteWithFlags() returns early when lastArg == "--"
parseFlags() strips -- from args during completion, so lastArg becomes empty
parseFlags() drops unknown/partial flags like --c from posArgs before they reach the completion handler
Want to fix this yourself?
Yes, I have a fix ready.
My urfave/cli version is
v3 (a9261cf)
Checklist
Dependency Management
Describe the bug
Shell completion does not show flag suggestions when the user types
--<TAB>or--partial<TAB>.To reproduce
myapp --<TAB>ormyapp --partial<TAB>Observed behavior
myapp --<TAB>produces no completionsmyapp --prefix<TAB>produces no completionsmyapp -<TAB>appends another-and produces flag completions (correct)Expected behavior
myapp --<TAB>should show all available flags (--config,--verbose,--help)myapp --prefix<TAB>should show all matching flagsAdditional context
The bug has four root causes:
checkShellCompleteFlag()disables completion mode when--appears anywhere in arguments, but--is the token being completedDefaultCompleteWithFlags()returns early whenlastArg == "--"parseFlags()strips--from args during completion, solastArgbecomes emptyparseFlags()drops unknown/partial flags like--cfromposArgsbefore they reach the completion handlerWant to fix this yourself?
Yes, I have a fix ready.