| 28 | } |
| 29 | |
| 30 | func NewCmdEnable(f *cmdutil.Factory, runF func(*EnableOptions) error) *cobra.Command { |
| 31 | opts := &EnableOptions{ |
| 32 | IO: f.IOStreams, |
| 33 | HttpClient: f.HttpClient, |
| 34 | Prompter: f.Prompter, |
| 35 | } |
| 36 | |
| 37 | cmd := &cobra.Command{ |
| 38 | Use: "enable [<workflow-id> | <workflow-name>]", |
| 39 | Short: "Enable a workflow", |
| 40 | Long: "Enable a workflow, allowing it to be run and show up when listing workflows.", |
| 41 | Args: cobra.MaximumNArgs(1), |
| 42 | RunE: func(cmd *cobra.Command, args []string) error { |
| 43 | // support `-R, --repo` override |
| 44 | opts.BaseRepo = f.BaseRepo |
| 45 | |
| 46 | if len(args) > 0 { |
| 47 | opts.Selector = args[0] |
| 48 | } else if !opts.IO.CanPrompt() { |
| 49 | return cmdutil.FlagErrorf("workflow ID or name required when not running interactively") |
| 50 | } else { |
| 51 | opts.Prompt = true |
| 52 | } |
| 53 | |
| 54 | if runF != nil { |
| 55 | return runF(opts) |
| 56 | } |
| 57 | return runEnable(opts) |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | return cmd |
| 62 | } |
| 63 | |
| 64 | func runEnable(opts *EnableOptions) error { |
| 65 | c, err := opts.HttpClient() |