NewPauseCmd creates and returns a pause command for Crawlers.
(f *cmdutil.Factory, runF func(*PauseOptions) error)
| 26 | |
| 27 | // NewPauseCmd creates and returns a pause command for Crawlers. |
| 28 | func NewPauseCmd(f *cmdutil.Factory, runF func(*PauseOptions) error) *cobra.Command { |
| 29 | opts := &PauseOptions{ |
| 30 | IO: f.IOStreams, |
| 31 | Config: f.Config, |
| 32 | CrawlerClient: f.CrawlerClient, |
| 33 | PrintFlags: cmdutil.NewPrintFlags().WithDefaultOutput("json"), |
| 34 | } |
| 35 | cmd := &cobra.Command{ |
| 36 | Use: "pause <crawler_id>...", |
| 37 | Args: cobra.MinimumNArgs(1), |
| 38 | ValidArgsFunction: cmdutil.CrawlerIDs(opts.CrawlerClient), |
| 39 | Short: "Pause one or multiple crawlers", |
| 40 | Long: heredoc.Doc(` |
| 41 | Pauses the specified crawler. |
| 42 | `), |
| 43 | Example: heredoc.Doc(` |
| 44 | # Pause the crawler with the ID "my-crawler" |
| 45 | $ algolia crawler pause my-crawler |
| 46 | |
| 47 | # Pause the crawlers with the IDs "my-crawler-1" and "my-crawler-2" |
| 48 | $ algolia crawler pause my-crawler-1 my-crawler-2 |
| 49 | `), |
| 50 | RunE: func(cmd *cobra.Command, args []string) error { |
| 51 | opts.IDs = args |
| 52 | if runF != nil { |
| 53 | return runF(opts) |
| 54 | } |
| 55 | |
| 56 | return runPauseCmd(opts) |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | cmd.Flags().BoolVar(&opts.DryRun, "dry-run", false, "Validate and preview the pause request without sending it") |
| 61 | opts.PrintFlags.AddFlags(cmd) |
| 62 | |
| 63 | return cmd |
| 64 | } |
| 65 | |
| 66 | func runPauseCmd(opts *PauseOptions) error { |
| 67 | if opts.DryRun { |