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

Function completeSessionIDs

cmd/opencodereview/session_cmd.go:101–123  ·  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. It completes one positional; a command with two session ids (compare) resets args per positional.

(cmd *cobra.Command, args []string, toComplete string)

Source from the content-addressed store, hash-verified

99// short summary as the completion description. It completes one positional;
100// a command with two session ids (compare) resets args per positional.
101func completeSessionIDs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
102 if len(args) != 0 {
103 return nil, cobra.ShellCompDirectiveNoFileComp
104 }
105 repo, _ := cmd.Flags().GetString("repo")
106 resolvedRepo, err := resolveWorkingDirForSession(repo)
107 if err != nil {
108 return nil, cobra.ShellCompDirectiveNoFileComp
109 }
110 summaries, err := session.ListSessions(resolvedRepo)
111 if err != nil {
112 return nil, cobra.ShellCompDirectiveNoFileComp
113 }
114 completions := make([]string, 0, len(summaries))
115 for _, s := range summaries {
116 if !strings.HasPrefix(s.SessionID, toComplete) {
117 continue
118 }
119 desc := fmt.Sprintf("%s · %d comments · %s", describeStart(s), s.TotalComments, describeStatus(s))
120 completions = append(completions, s.SessionID+"\t"+desc)
121 }
122 return completions, cobra.ShellCompDirectiveNoFileComp
123}
124
125func init() {
126 sessionListCmd.Flags().StringVar(&sessionListRepoDir, "repo", "", "root directory of the git repository (default: current dir)")

Callers 3

session_cmd.goFile · 0.85
TestCompleteSessionIDsFunction · 0.85

Calls 4

ListSessionsFunction · 0.92
describeStartFunction · 0.85
describeStatusFunction · 0.85

Tested by 2

TestCompleteSessionIDsFunction · 0.68