NewCmdList creates the list command
(f *cmdutil.Factory, runF func(*ListOptions) error)
| 30 | |
| 31 | // NewCmdList creates the list command |
| 32 | func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { |
| 33 | opts := &ListOptions{ |
| 34 | IO: f.IOStreams, |
| 35 | CapiClient: shared.CapiClientFunc(f), |
| 36 | Limit: defaultLimit, |
| 37 | Browser: f.Browser, |
| 38 | } |
| 39 | |
| 40 | cmd := &cobra.Command{ |
| 41 | Use: "list", |
| 42 | Short: "List agent tasks (preview)", |
| 43 | Args: cobra.NoArgs, |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | if opts.Limit < 1 { |
| 46 | return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit) |
| 47 | } |
| 48 | if runF != nil { |
| 49 | return runF(opts) |
| 50 | } |
| 51 | return listRun(opts) |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | cmd.Flags().IntVarP(&opts.Limit, "limit", "L", defaultLimit, "Maximum number of agent tasks to fetch") |
| 56 | cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open agent tasks in the browser") |
| 57 | |
| 58 | cmdutil.AddJSONFlags(cmd, &opts.Exporter, capi.SessionFields) |
| 59 | |
| 60 | return cmd |
| 61 | } |
| 62 | |
| 63 | func listRun(opts *ListOptions) error { |
| 64 | if opts.Web { |