completeSessionIDs offers the persisted session ids for the current repo (or --repo, when already typed) as shell completions, newest first, with a short summary as the completion description.
(cmd *cobra.Command, args []string, toComplete string)
| 75 | // (or --repo, when already typed) as shell completions, newest first, with a |
| 76 | // short summary as the completion description. |
| 77 | func completeSessionIDs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 78 | if len(args) != 0 { |
| 79 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 80 | } |
| 81 | repo, _ := cmd.Flags().GetString("repo") |
| 82 | resolvedRepo, err := resolveWorkingDirForSession(repo) |
| 83 | if err != nil { |
| 84 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 85 | } |
| 86 | summaries, err := session.ListSessions(resolvedRepo) |
| 87 | if err != nil { |
| 88 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 89 | } |
| 90 | completions := make([]string, 0, len(summaries)) |
| 91 | for _, s := range summaries { |
| 92 | if !strings.HasPrefix(s.SessionID, toComplete) { |
| 93 | continue |
| 94 | } |
| 95 | desc := fmt.Sprintf("%s · %d comments · %s", describeStart(s), s.TotalComments, describeStatus(s)) |
| 96 | completions = append(completions, s.SessionID+"\t"+desc) |
| 97 | } |
| 98 | return completions, cobra.ShellCompDirectiveNoFileComp |
| 99 | } |
| 100 | |
| 101 | func init() { |
| 102 | sessionListCmd.Flags().StringVar(&sessionListRepoDir, "repo", "", "root directory of the git repository (default: current dir)") |