diff options
author | Johannes Altmanninger <aclopte@gmail.com> | 2021-01-24 14:05:40 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2022-05-01 10:54:13 +0200 |
commit | bc6ba02bd84fc3bd86c61e89c16c400dfef01623 (patch) | |
tree | d6a88de7569493795544eedeb962a1dc859b8e71 /commands/ls.go | |
parent | 8ee333582ff82d0df971309e94946f2f6e69475b (diff) | |
download | git-bug-bc6ba02bd84fc3bd86c61e89c16c400dfef01623.tar.gz git-bug-bc6ba02bd84fc3bd86c61e89c16c400dfef01623.zip |
Add command-specific argument completions
Complete bug IDs, bridges, users, labels where appropriate.
This works in bash and fish. ZSH is not yet supported by Cobra.
In fish, descriptions (the part of a completion after the "\t") are shown
as completion label, and can be searched with Ctrl+S.
Reproduce with
fish -C 'source misc/fish_completion/git-bug'
git bug select ^I
(tested with fish version 3.3.1)
Also works with bash, but only for "git-bug" (with the dash)
bash --rcfile <(echo source misc/bash_completion/git-bug)
git-bug select ^I
Closes #493
Diffstat (limited to 'commands/ls.go')
-rw-r--r-- | commands/ls.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/commands/ls.go b/commands/ls.go index db4145d0..909e25a8 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -56,6 +56,7 @@ git bug ls status:open --by creation "foo bar" baz RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { return runLs(env, options, args) }), + ValidArgsFunction: completeLs(env), } flags := cmd.Flags() @@ -63,26 +64,36 @@ git bug ls status:open --by creation "foo bar" baz flags.StringSliceVarP(&options.statusQuery, "status", "s", nil, "Filter by status. Valid values are [open,closed]") + cmd.RegisterFlagCompletionFunc("status", completeFrom([]string{"open", "closed"})) flags.StringSliceVarP(&options.authorQuery, "author", "a", nil, "Filter by author") flags.StringSliceVarP(&options.metadataQuery, "metadata", "m", nil, "Filter by metadata. Example: github-url=URL") + cmd.RegisterFlagCompletionFunc("author", completeUserForQuery(env)) flags.StringSliceVarP(&options.participantQuery, "participant", "p", nil, "Filter by participant") + cmd.RegisterFlagCompletionFunc("participant", completeUserForQuery(env)) flags.StringSliceVarP(&options.actorQuery, "actor", "A", nil, "Filter by actor") + cmd.RegisterFlagCompletionFunc("actor", completeUserForQuery(env)) flags.StringSliceVarP(&options.labelQuery, "label", "l", nil, "Filter by label") + cmd.RegisterFlagCompletionFunc("label", completeLabel(env)) flags.StringSliceVarP(&options.titleQuery, "title", "t", nil, "Filter by title") flags.StringSliceVarP(&options.noQuery, "no", "n", nil, "Filter by absence of something. Valid values are [label]") + cmd.RegisterFlagCompletionFunc("no", completeLabel(env)) flags.StringVarP(&options.sortBy, "by", "b", "creation", "Sort the results by a characteristic. Valid values are [id,creation,edit]") + cmd.RegisterFlagCompletionFunc("by", completeFrom([]string{"id", "creation", "edit"})) flags.StringVarP(&options.sortDirection, "direction", "d", "asc", "Select the sorting direction. Valid values are [asc,desc]") + cmd.RegisterFlagCompletionFunc("direction", completeFrom([]string{"asc", "desc"})) flags.StringVarP(&options.outputFormat, "format", "f", "default", "Select the output formatting style. Valid values are [default,plain,json,org-mode]") + cmd.RegisterFlagCompletionFunc("format", + completeFrom([]string{"default", "plain", "json", "org-mode"})) return cmd } |