Skip to content
Myr

Handle linebreaks in custom completions. (#1162)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

If a command/flag description contains a linebreak then the shell completion script will interpret this as new command/flag. To fix this we only use the first line from the description in the output.

authored by Luap99 · committed by GitHub · parent 50258f1 · Browse files · 2 files+7 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Paul Holzinger <paul.holzinger@web.de>

Diff stats

2 files+7 added−1 removed

  • other:+7 added−1 removed

2 files+7 added−1 removed

modified:custom_completions_test.go+1 added-1 removed
559 unmodified lines
560 Run: emptyRun,561 }562 rootCmd.AddCommand(childCmd)563564 rootCmd.Flags().IntP("first", "f", -1, "first flag")564 rootCmd.Flags().IntP("first", "f", -1, "first flag\nlonger description for flag")565 rootCmd.PersistentFlags().BoolP("second", "s", false, "second flag")566 childCmd.Flags().String("subFlag", "", "sub flag")567568 // Test that flag names are not shown if the user has not given the '-' prefix
1392 unmodified lines
modified:custom_completions.go+6 added
130 unmodified lines
131 // Remove any description that may be included following a tab character.132 comp = strings.Split(comp, "\t")[0]133 }134135 // Make sure we only write the first line to the output.136 // This is needed if a description contains a linebreak.137 // Otherwise the shell scripts will interpret the other lines as new flags138 // and could therefore provide a wrong completion.139 comp = strings.Split(comp, "\n")[0]140141 // Finally trim the completion. This is especially important to get rid142 // of a trailing tab when there are no description following it.143 // For example, a sub-command without a description should not be completed144 // with a tab at the end (or else zsh will show a -- following it
413 unmodified lines