MCPcopy Create free account
hub / github.com/algolia/cli / NewPauseCmd

Function NewPauseCmd

pkg/cmd/crawler/pause/pause.go:28–64  ·  view source on GitHub ↗

NewPauseCmd creates and returns a pause command for Crawlers.

(f *cmdutil.Factory, runF func(*PauseOptions) error)

Source from the content-addressed store, hash-verified

26
27// NewPauseCmd creates and returns a pause command for Crawlers.
28func 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
66func runPauseCmd(opts *PauseOptions) error {
67 if opts.DryRun {

Callers 3

NewCrawlersCmdFunction · 0.92
TestNewPauseCmdFunction · 0.85

Calls 5

NewPrintFlagsFunction · 0.92
CrawlerIDsFunction · 0.92
runPauseCmdFunction · 0.85
WithDefaultOutputMethod · 0.80
AddFlagsMethod · 0.45

Tested by 2

TestNewPauseCmdFunction · 0.68