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

Function NewRemoveCmd

pkg/cmd/profile/remove/remove.go:28–80  ·  view source on GitHub ↗

NewRemoveCmd returns a new instance of RemoveCmd

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

Source from the content-addressed store, hash-verified

26
27// NewRemoveCmd returns a new instance of RemoveCmd
28func NewRemoveCmd(f *cmdutil.Factory, runF func(*RemoveOptions) error) *cobra.Command {
29 opts := &RemoveOptions{
30 IO: f.IOStreams,
31 config: f.Config,
32 }
33
34 var confirm bool
35
36 cmd := &cobra.Command{
37 Use: "remove <profile>",
38 Args: validators.ExactArgs(1),
39 ValidArgsFunction: cmdutil.ConfiguredProfilesCompletionFunc(f),
40 Short: "Remove the specified profile",
41 Long: `Remove the specified profile from the configuration.`,
42 Example: heredoc.Doc(`
43 # Remove the profile named "my-app" from the configuration
44 $ algolia profile remove my-app
45 `),
46 RunE: func(cmd *cobra.Command, args []string) error {
47 opts.Profile = args[0]
48
49 if opts.config.Default() != nil {
50 opts.DefaultProfile = opts.config.Default().Name
51 } else {
52 opts.DefaultProfile = ""
53 }
54
55 if !confirm && opts.Profile == opts.DefaultProfile {
56 if !opts.IO.CanPrompt() {
57 return cmdutil.FlagErrorf(
58 "--confirm required when non-interactive shell is detected",
59 )
60 }
61 opts.DoConfirm = true
62 }
63
64 if !opts.config.ProfileExists(opts.Profile) {
65 return fmt.Errorf("the specified profile does not exist: '%s'", opts.Profile)
66 }
67
68 if runF != nil {
69 return runF(opts)
70 }
71
72 return runRemoveCmd(opts)
73 },
74 }
75
76 cmd.Flags().
77 BoolVarP(&confirm, "confirm", "y", false, "Skip the remove profile confirmation prompt")
78
79 return cmd
80}
81
82// runRemoveCmd executes the remove command
83func runRemoveCmd(opts *RemoveOptions) error {

Callers 3

NewProfileCmdFunction · 0.92
TestNewRemoveCmdFunction · 0.85
Test_runRemoveCmdFunction · 0.85

Calls 8

ExactArgsFunction · 0.92
FlagErrorfFunction · 0.92
runRemoveCmdFunction · 0.85
CanPromptMethod · 0.80
DefaultMethod · 0.65
ProfileExistsMethod · 0.65
ErrorfMethod · 0.65

Tested by 2

TestNewRemoveCmdFunction · 0.68
Test_runRemoveCmdFunction · 0.68