Conversation
a7eea0b to
c06c926
Compare
6c066ff to
84addde
Compare
|
|
Use https://cli.urfave.org/v3/examples/completions/shell-completions as a reference for completions. The previous version completed "-" -> "--" -> "--help,", but the added comma was incorrect, as no such flag exists and the tool does not accept it. A similar issue occurred with "--version", which was shown as "--version,". The root cause was that completion was explicitly disabled for this case: $ greet -- --generate-shell-completion As a result, it printed the default help message: > NAME: > greet - A new cli application > > USAGE: > greet [global options] [command [command options]] > > COMMANDS: > add, a add a task to the list > complete, c complete a task on the list > template, t options for task templates > help, h Shows a list of commands or help for one command > > GLOBAL OPTIONS: > --help, -h show help Bash used "--help," as a flag suggestion, which was incorrect. In this commit, completion is enabled for the "-- --generate-shell-completion" case, and a test is added to verify correct behavior. With this change, both "-" and "--" now complete to "--help", which is correct.
84addde to
f757d4d
Compare
|
@abitrolly if Check how common tools behave when TAB is pressed after In |
|
@dearchap I suspect that my fix is not sufficient to completely fix I tried to reproduce this in tests and wrote this: func ExampleCommand_Run_shellComplete_bash_withDoubleDashFlag_Subcommand() {
cmd := &cli.Command{
Name: "greet",
EnableShellCompletion: true,
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "other",
Aliases: []string{"o"},
},
&cli.StringFlag{
Name: "xyz",
Aliases: []string{"x"},
},
},
Commands: []*cli.Command{
{
Name: "subcmd",
EnableShellCompletion: true,
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "aaa",
},
&cli.StringFlag{
Name: "bbb",
},
},
},
},
}
// Simulate a bash environment and command line arguments
os.Setenv("SHELL", "bash")
os.Args = []string{
"greet", "--other", "1",
"subcmd", "--",
"--generate-shell-completion",
}
_ = cmd.Run(context.Background(), os.Args)
// Output:
// --aaa
// --bbb
// --help
}This should return the list of options, but it produces the help message instead. Could you help with this one, please? Maybe I'm missing something. |
What type of PR is this?
(REQUIRED)
What this PR does / why we need it:
(REQUIRED)
Currently "--" is completed to "--help," (note the comma!)
This PR fixes it so it completed to "--help" without the comma.
Which issue(s) this PR fixes:
(REQUIRED)
Fixes #1993
Reverts #1933
Special notes for your reviewer:
(fill-in or delete this section)
If the approach is accepted it makes sense to fix this in v2 as well.
Testing
(fill-in or delete this section)
You can compile the example given for completion here: https://cli.urfave.org/v3/examples/completions/shell-completions and verify what happens you you type "greet --" and press TAB.
Release Notes
(REQUIRED)