mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
cmd/tailscale/cli/ffcomplete: omit and clean completion results
Updates #3793 Signed-off-by: Paul Scott <paul@tailscale.com>
This commit is contained in:
parent
fa1303d632
commit
ba34943133
@ -193,12 +193,26 @@ func Complete(root *ffcli.Command, args []string, startFlags, descs bool) (words
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Strip any descriptions if they were suppressed.
|
// Strip any descriptions if they were suppressed.
|
||||||
if !descs {
|
clean := words[:0]
|
||||||
for i := range words {
|
for _, w := range words {
|
||||||
words[i], _, _ = strings.Cut(words[i], "\t")
|
if !descs {
|
||||||
|
w, _, _ = strings.Cut(w, "\t")
|
||||||
}
|
}
|
||||||
|
w = cutAny(w, "\n\r")
|
||||||
|
if w == "" || w[0] == '\t' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
clean = append(clean, w)
|
||||||
}
|
}
|
||||||
return words, dir, nil
|
return clean, dir, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func cutAny(s, cutset string) string {
|
||||||
|
i := strings.IndexAny(s, cutset)
|
||||||
|
if i == -1 {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return s[:i]
|
||||||
}
|
}
|
||||||
|
|
||||||
// splitFlagArgs separates a list of command-line arguments into arguments
|
// splitFlagArgs separates a list of command-line arguments into arguments
|
||||||
|
@ -50,11 +50,17 @@ func() *ffcli.Command {
|
|||||||
cmd := &ffcli.Command{
|
cmd := &ffcli.Command{
|
||||||
Name: "ping",
|
Name: "ping",
|
||||||
FlagSet: newFlagSet("prog ping", flag.ContinueOnError, func(fs *flag.FlagSet) {
|
FlagSet: newFlagSet("prog ping", flag.ContinueOnError, func(fs *flag.FlagSet) {
|
||||||
fs.String("until", "", "when pinging should end")
|
fs.String("until", "", "when pinging should end\nline break!")
|
||||||
ffcomplete.Flag(fs, "until", ffcomplete.Fixed("forever", "direct"))
|
ffcomplete.Flag(fs, "until", ffcomplete.Fixed("forever", "direct"))
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
ffcomplete.Args(cmd, ffcomplete.Fixed("jupiter", "neptune", "venus"))
|
ffcomplete.Args(cmd, ffcomplete.Fixed(
|
||||||
|
"jupiter\t5th planet\nand largets",
|
||||||
|
"neptune\t8th planet",
|
||||||
|
"venus\t2nd planet",
|
||||||
|
"\tonly description",
|
||||||
|
"\nonly line break",
|
||||||
|
))
|
||||||
return cmd
|
return cmd
|
||||||
}(),
|
}(),
|
||||||
},
|
},
|
||||||
@ -170,9 +176,9 @@ func() *ffcli.Command {
|
|||||||
showDescs: true,
|
showDescs: true,
|
||||||
wantComp: []string{
|
wantComp: []string{
|
||||||
"--until\twhen pinging should end",
|
"--until\twhen pinging should end",
|
||||||
"jupiter",
|
"jupiter\t5th planet",
|
||||||
"neptune",
|
"neptune\t8th planet",
|
||||||
"venus",
|
"venus\t2nd planet",
|
||||||
},
|
},
|
||||||
wantDir: ffcomplete.ShellCompDirectiveNoFileComp,
|
wantDir: ffcomplete.ShellCompDirectiveNoFileComp,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user