| 33 | } |
| 34 | |
| 35 | func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { |
| 36 | opts := &ListOptions{ |
| 37 | IO: f.IOStreams, |
| 38 | HttpClient: f.HttpClient, |
| 39 | } |
| 40 | |
| 41 | cmd := &cobra.Command{ |
| 42 | Use: "list", |
| 43 | Short: "List workflows", |
| 44 | Long: "List workflow files, hiding disabled workflows by default.", |
| 45 | Aliases: []string{"ls"}, |
| 46 | Args: cobra.NoArgs, |
| 47 | RunE: func(cmd *cobra.Command, args []string) error { |
| 48 | // support `-R, --repo` override |
| 49 | opts.BaseRepo = f.BaseRepo |
| 50 | |
| 51 | if opts.Limit < 1 { |
| 52 | return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit) |
| 53 | } |
| 54 | |
| 55 | if runF != nil { |
| 56 | return runF(opts) |
| 57 | } |
| 58 | |
| 59 | return listRun(opts) |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | cmd.Flags().IntVarP(&opts.Limit, "limit", "L", defaultLimit, "Maximum number of workflows to fetch") |
| 64 | cmd.Flags().BoolVarP(&opts.All, "all", "a", false, "Include disabled workflows") |
| 65 | cmdutil.AddJSONFlags(cmd, &opts.Exporter, workflowFields) |
| 66 | return cmd |
| 67 | } |
| 68 | |
| 69 | func listRun(opts *ListOptions) error { |
| 70 | repo, err := opts.BaseRepo() |