Skip to content

Commit

Permalink
Merge pull request #520 from CircleCI-Public/no-prompt-admin
Browse files Browse the repository at this point in the history
[CIRCLE-31080] Add no-prompt option to admin commands
  • Loading branch information
circlecai authored Nov 20, 2020
2 parents 44f80c2 + 4ab36a6 commit 10b61a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func newAdminCommand(config *settings.Config) *cobra.Command {
Args: cobra.MinimumNArgs(1),
}
importOrbCommand.Flags().BoolVar(&orbOpts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI.")
if err := importOrbCommand.Flags().MarkHidden("integration-testing"); err != nil {
panic(err)
}
importOrbCommand.Flags().BoolVar(&orbOpts.noPrompt, "no-prompt", false, "Disable prompt to bypass interactive UI.")

renameCommand := &cobra.Command{
Use: "rename-namespace <old-name> <new-name>",
Expand Down Expand Up @@ -61,13 +65,23 @@ Example:
return validateToken(nsOpts.cfg)
},
RunE: func(_ *cobra.Command, _ []string) error {
if nsOpts.integrationTesting {
nsOpts.tty = createNamespaceTestUI{
confirm: true,
}
}
return deleteNamespaceAlias(nsOpts)
},
Args: cobra.ExactArgs(1),
Annotations: make(map[string]string),
}

deleteAliasCommand.Annotations["<name>"] = "The name of the alias to delete"
deleteAliasCommand.Flags().BoolVar(&nsOpts.noPrompt, "no-prompt", false, "Disable prompt to bypass interactive UI.")
deleteAliasCommand.Flags().BoolVar(&nsOpts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI.")
if err := deleteAliasCommand.Flags().MarkHidden("integration-testing"); err != nil {
panic(err)
}

adminCommand := &cobra.Command{
Use: "admin",
Expand Down
1 change: 1 addition & 0 deletions cmd/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var _ = Describe("Namespace integration tests", func() {
"--skip-update-check",
"--token", token,
"--host", tempSettings.TestServer.URL(),
"--integration-testing",
"foo-ns",
)
})
Expand Down
8 changes: 6 additions & 2 deletions cmd/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ Please note that at this time all namespaces created in the registry are world-r

func deleteNamespaceAlias(opts namespaceOptions) error {
aliasName := opts.args[0]
err := api.DeleteNamespaceAlias(opts.cl, aliasName)
return err
confirm := fmt.Sprintf("Are you sure you wish to delete the namespace alias %s? You should make sure that all configs and orbs that refer to it this way are updated to the new name first.", aliasName)
if opts.noPrompt || opts.tty.askUserToConfirm(confirm) {
err := api.DeleteNamespaceAlias(opts.cl, aliasName)
return err
}
return nil
}

func createNamespace(opts namespaceOptions) error {
Expand Down

0 comments on commit 10b61a8

Please sign in to comment.