MCPcopy Create free account
hub / github.com/alibaba/open-code-review / completeSessionIDs

Function completeSessionIDs

cmd/opencodereview/session_cmd.go:77–99  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

75// (or --repo, when already typed) as shell completions, newest first, with a
76// short summary as the completion description.
77func 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
101func init() {
102 sessionListCmd.Flags().StringVar(&sessionListRepoDir, "repo", "", "root directory of the git repository (default: current dir)")

Callers 2

TestCompleteSessionIDsFunction · 0.85

Calls 4

ListSessionsFunction · 0.92
describeStartFunction · 0.85
describeStatusFunction · 0.85

Tested by 2

TestCompleteSessionIDsFunction · 0.68