runUnblockCmd executes the unblock command.
(opts *UnblockOptions)
| 82 | |
| 83 | // runUnblockCmd executes the unblock command. |
| 84 | func runUnblockCmd(opts *UnblockOptions) error { |
| 85 | client, err := opts.CrawlerClient() |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | |
| 90 | // Get the crawler and check if it is actually blocked. |
| 91 | crawler, err := client.Get(opts.ID, false) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | if crawler.BlockingTaskID == "" { |
| 96 | return fmt.Errorf("crawler %q is not blocked", opts.ID) |
| 97 | } |
| 98 | |
| 99 | if opts.DryRun { |
| 100 | summary := map[string]any{ |
| 101 | "action": "unblock_crawler", |
| 102 | "id": opts.ID, |
| 103 | "blockingError": crawler.BlockingError, |
| 104 | "dryRun": true, |
| 105 | } |
| 106 | |
| 107 | return cmdutil.PrintRunSummary( |
| 108 | opts.IO, |
| 109 | opts.PrintFlags, |
| 110 | summary, |
| 111 | fmt.Sprintf("Dry run: would unblock crawler %s (%s)", crawler.Name, opts.ID), |
| 112 | ) |
| 113 | } |
| 114 | |
| 115 | if opts.DoConfirm { |
| 116 | var confirmed bool |
| 117 | err := prompt.Confirm( |
| 118 | fmt.Sprintf( |
| 119 | "Are you sure you want to unblock the crawler %q? \nBlocking error is: %s", |
| 120 | opts.ID, |
| 121 | crawler.BlockingError, |
| 122 | ), |
| 123 | &confirmed, |
| 124 | ) |
| 125 | if err != nil { |
| 126 | return fmt.Errorf("failed to prompt: %w", err) |
| 127 | } |
| 128 | if !confirmed { |
| 129 | return nil |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Cancel the task blocking the crawler. |
| 134 | if err := client.CancelTask(crawler.ID, crawler.BlockingTaskID); err != nil { |
| 135 | return err |
| 136 | } |
| 137 | |
| 138 | cs := opts.IO.ColorScheme() |
| 139 | if opts.IO.IsStdoutTTY() { |
| 140 | fmt.Fprintf(opts.IO.Out, "%s Unblocked crawler %s\n", cs.SuccessIcon(), cs.Bold(opts.ID)) |
| 141 | } |
no test coverage detected