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

Function NewUnblockCmd

pkg/cmd/crawler/unblock/unblock.go:31–81  ·  view source on GitHub ↗

NewUnblockCmd creates and returns a command to unblock a crawler.

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

Source from the content-addressed store, hash-verified

29
30// NewUnblockCmd creates and returns a command to unblock a crawler.
31func NewUnblockCmd(f *cmdutil.Factory, runF func(*UnblockOptions) error) *cobra.Command {
32 opts := &UnblockOptions{
33 IO: f.IOStreams,
34 Config: f.Config,
35 CrawlerClient: f.CrawlerClient,
36 PrintFlags: cmdutil.NewPrintFlags().WithDefaultOutput("json"),
37 }
38
39 var confirm bool
40
41 cmd := &cobra.Command{
42 Use: "unblock <crawler_id>",
43 Args: cobra.ExactArgs(1),
44 ValidArgsFunction: cmdutil.CrawlerIDs(opts.CrawlerClient),
45 Short: "Unblock a crawler",
46 Long: heredoc.Doc(`
47 Unblock a crawler by cancelling the specific task that is currently blocking it.
48 `),
49 Example: heredoc.Doc(`
50 # Unblock the crawler with the ID "my-crawler"
51 $ algolia crawler unblock my-crawler
52 `),
53 RunE: func(cmd *cobra.Command, args []string) error {
54 opts.ID = args[0]
55 if err := cmdutil.ValidateNoControlChars("crawler_id", opts.ID); err != nil {
56 return err
57 }
58 if runF != nil {
59 return runF(opts)
60 }
61
62 if !confirm && !opts.DryRun {
63 if !opts.IO.CanPrompt() {
64 return cmdutil.FlagErrorf(
65 "--confirm required when non-interactive shell is detected",
66 )
67 }
68 opts.DoConfirm = true
69 }
70
71 return runUnblockCmd(opts)
72 },
73 }
74
75 cmd.Flags().
76 BoolVarP(&confirm, "confirm", "y", false, "Skip the unblock crawler confirmation prompt")
77 cmd.Flags().BoolVar(&opts.DryRun, "dry-run", false, "Validate and preview the unblock request without sending it")
78 opts.PrintFlags.AddFlags(cmd)
79
80 return cmd
81}
82
83// runUnblockCmd executes the unblock command.
84func runUnblockCmd(opts *UnblockOptions) error {

Calls 8

NewPrintFlagsFunction · 0.92
CrawlerIDsFunction · 0.92
ValidateNoControlCharsFunction · 0.92
FlagErrorfFunction · 0.92
runUnblockCmdFunction · 0.85
WithDefaultOutputMethod · 0.80
CanPromptMethod · 0.80
AddFlagsMethod · 0.45