| 175 | } |
| 176 | |
| 177 | func completeSessionIDs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 178 | if len(args) != 0 { |
| 179 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 180 | } |
| 181 | repo, _ := cmd.Flags().GetString("repo") |
| 182 | resolvedRepo, err := resolveWorkingDirForSession(repo) |
| 183 | if err != nil { |
| 184 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 185 | } |
| 186 | summaries, err := session.ListSessions(resolvedRepo) |
| 187 | if err != nil { |
| 188 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 189 | } |
| 190 | completions := make([]string, 0, len(summaries)) |
| 191 | for _, s := range summaries { |
| 192 | if !strings.HasPrefix(s.SessionID, toComplete) { |
| 193 | continue |
| 194 | } |
| 195 | desc := fmt.Sprintf("%s · %d comments · %s", describeStart(s), s.TotalComments, describeStatus(s)) |
| 196 | completions = append(completions, s.SessionID+"\t"+desc) |
| 197 | } |
| 198 | return completions, cobra.ShellCompDirectiveNoFileComp |
| 199 | } |
| 200 | |
| 201 | func init() { |
| 202 | sessionListCmd.Flags().StringVar(&sessionListRepoDir, "repo", "", "root directory of the git repository (default: current dir)") |