(deps commandDeps)
| 150 | } |
| 151 | |
| 152 | func newSessionListCommand(deps commandDeps) *cobra.Command { |
| 153 | var ( |
| 154 | includeAll bool |
| 155 | workspaceFilter string |
| 156 | resumable bool |
| 157 | limit int |
| 158 | ) |
| 159 | |
| 160 | cmd := &cobra.Command{ |
| 161 | Use: sessionListKey, |
| 162 | Short: "List sessions", |
| 163 | Example: ` # List active sessions |
| 164 | agh session list |
| 165 | |
| 166 | # Include stopped sessions and filter to a workspace |
| 167 | agh session list --all --workspace checkout-api`, |
| 168 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 169 | client, err := clientFromDeps(deps) |
| 170 | if err != nil { |
| 171 | return err |
| 172 | } |
| 173 | |
| 174 | sessions, err := client.ListSessions(cmd.Context(), SessionListQuery{ |
| 175 | Workspace: workspaceFilter, |
| 176 | Resumable: resumable, |
| 177 | Limit: limit, |
| 178 | Sort: sessionListSortKey(resumable), |
| 179 | }) |
| 180 | if err != nil { |
| 181 | return err |
| 182 | } |
| 183 | if !includeAll && !resumable { |
| 184 | sessions = filterActiveSessions(sessions) |
| 185 | } |
| 186 | |
| 187 | return writeCommandOutput(cmd, sessionListBundle(sessions, deps.now)) |
| 188 | }, |
| 189 | } |
| 190 | cmd.Flags().BoolVar(&includeAll, "all", false, "Include stopped sessions") |
| 191 | cmd.Flags().StringVar(&workspaceFilter, workspaceSkillSource, "", "Filter by workspace name or ID") |
| 192 | cmd.Flags().BoolVar(&resumable, "resumable", false, "Show only sessions eligible for resume attach") |
| 193 | cmd.Flags().IntVar(&limit, "limit", 0, "Maximum sessions to return") |
| 194 | return cmd |
| 195 | } |
| 196 | |
| 197 | func sessionListSortKey(resumable bool) string { |
| 198 | if resumable { |
no test coverage detected