(deps commandDeps)
| 136 | } |
| 137 | |
| 138 | func newHooksRunsCommand(deps commandDeps) *cobra.Command { |
| 139 | var ( |
| 140 | query HookRunsQuery |
| 141 | sinceRaw string |
| 142 | workspaceRef string |
| 143 | ) |
| 144 | |
| 145 | cmd := &cobra.Command{ |
| 146 | Use: "runs", |
| 147 | Short: "Show persisted hook execution history", |
| 148 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 149 | client, err := clientFromDeps(deps) |
| 150 | if err != nil { |
| 151 | return err |
| 152 | } |
| 153 | if strings.TrimSpace(query.Session) == "" { |
| 154 | return errors.New("cli: --session is required") |
| 155 | } |
| 156 | |
| 157 | since, err := parseSinceFlag(sinceRaw, deps.now) |
| 158 | if err != nil { |
| 159 | return err |
| 160 | } |
| 161 | if !since.IsZero() { |
| 162 | query.Since = since.UTC().Format(time.RFC3339Nano) |
| 163 | } |
| 164 | |
| 165 | workspace, err := resolveCLIWorkspaceRouteRef(cmd.Context(), deps, client, workspaceRef) |
| 166 | if err != nil { |
| 167 | return err |
| 168 | } |
| 169 | runs, err := client.HookRuns(cmd.Context(), workspace, query) |
| 170 | if err != nil { |
| 171 | return err |
| 172 | } |
| 173 | return writeCommandOutput(cmd, hookRunsBundle(runs)) |
| 174 | }, |
| 175 | } |
| 176 | |
| 177 | cmd.Flags().StringVar(&query.Session, "session", "", "Session ID") |
| 178 | cmd.Flags().StringVar(&query.Event, hooksEventKey, "", "Filter by hook event") |
| 179 | cmd.Flags().StringVar(&query.Outcome, cliOutcomeKey, "", "Filter by hook outcome") |
| 180 | cmd.Flags(). |
| 181 | StringVar(&sinceRaw, "since", "", "Show runs since an RFC3339 timestamp or relative duration") |
| 182 | cmd.Flags().IntVar(&query.Last, "last", 0, "Show only the most recent N runs") |
| 183 | cmd.Flags().StringVar(&workspaceRef, "workspace", "", "Workspace name, ID, or path") |
| 184 | return cmd |
| 185 | } |
| 186 | |
| 187 | func hookListBundle(hooks []HookCatalogRecord) outputBundle { |
| 188 | return listBundle( |
no test coverage detected