Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This completes bug IDs in bash and fish. I haven't gotten this to work in zsh. In fish, the bug titles are shown as completion label, and can be searched for. I don't know if/how other shells can show the completion label. Maybe they don't use "\t" as separator but it seems to do no harm. The interface does not yet seem ideal because sometimes subcommands and bug IDs are both valid. Since there can be lots of bug IDs, they overshadow the subcommands. I wonder if instead of git bug status open 0123acd we should use git bug status --open 0123acd or if there's some other way to avoid ambiguity. If that doesn't work out, fish has a -k/--keep-order flag, so subcommand completions can be listed before bug IDs, but that's neither portable nor a pretty solution. Part of #493
- Loading branch information
Showing
9 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package commands | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/MichaelMure/git-bug/cache" | ||
"github.com/MichaelMure/git-bug/query" | ||
) | ||
|
||
type validArgsFunction func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) | ||
|
||
func completeBugs(env *Env) validArgsFunction { | ||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
// Currently, the commands accept at most one bug ID. | ||
if len(args) != 0 { | ||
return nil, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
if err := loadBackend(env)(cmd, args); err != nil { | ||
log.Println(err) | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
defer func() { | ||
err := closeBackend(env)(cmd, args) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
}() | ||
|
||
q := query.NewQuery() | ||
allIds, err := env.backend.QueryBugs(q) | ||
if err != nil { | ||
log.Println(err) | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
|
||
bugExcerpt := make([]*cache.BugExcerpt, len(allIds)) | ||
for i, id := range allIds { | ||
bugExcerpt[i], err = env.backend.ResolveBugExcerpt(id) | ||
if err != nil { | ||
log.Println(err) | ||
return nil, cobra.ShellCompDirectiveError | ||
} | ||
} | ||
|
||
completions := make([]string, len(allIds)) | ||
for i, id := range allIds { | ||
completions[i] = id.Human() + "\t" + bugExcerpt[i].Title | ||
} | ||
return completions, cobra.ShellCompDirectiveDefault | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters