(state *globalState)
| 429 | } |
| 430 | |
| 431 | func (a *App) providerRemoveCommand(state *globalState) *cobra.Command { |
| 432 | var yes bool |
| 433 | cmd := &cobra.Command{ |
| 434 | Use: "remove NAME", |
| 435 | Aliases: []string{"rm", "delete"}, |
| 436 | Short: "Remove a provider", |
| 437 | Args: cobra.ExactArgs(1), |
| 438 | RunE: func(cmd *cobra.Command, args []string) error { |
| 439 | name := args[0] |
| 440 | if _, err := providerAPI(state).Show(context.Background(), name); err != nil { |
| 441 | return fmt.Errorf("provider %q not found", name) |
| 442 | } |
| 443 | if !yes { |
| 444 | // Non-interactive contexts (no TTY) must opt out via |
| 445 | // --yes so scripts don't hang on stdin. We bail with a |
| 446 | // clear error rather than silently skipping. |
| 447 | if !inIsTTY(cmd.InOrStdin()) { |
| 448 | return fmt.Errorf("remove requires --yes when stdin is not a TTY") |
| 449 | } |
| 450 | fmt.Fprintf(cmd.OutOrStdout(), "Remove provider %q? [y/N]: ", name) |
| 451 | answer := readLine(cmd.InOrStdin()) |
| 452 | if !strings.EqualFold(strings.TrimSpace(answer), "y") { |
| 453 | fmt.Fprintln(cmd.OutOrStdout(), "Aborted.") |
| 454 | return nil |
| 455 | } |
| 456 | } |
| 457 | if _, err := providerAPI(state).Remove(context.Background(), name); err != nil { |
| 458 | return err |
| 459 | } |
| 460 | fmt.Fprintf(cmd.OutOrStdout(), "Removed provider %q\n", name) |
| 461 | return nil |
| 462 | }, |
| 463 | } |
| 464 | cmd.Flags().BoolVarP(&yes, "yes", "y", false, "Do not prompt for confirmation") |
| 465 | return cmd |
| 466 | } |
| 467 | |
| 468 | func (a *App) providerEnableCommand(state *globalState) *cobra.Command { |
| 469 | return &cobra.Command{ |
no test coverage detected