Skip to content

Commit

Permalink
Refactor delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket committed Feb 26, 2021
1 parent ae526b5 commit b1990b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
8 changes: 1 addition & 7 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,9 @@ auth0 apis delete --id id
}
}

err := ansi.Spinner("Deleting API", func() error {
return ansi.Spinner("Deleting API", func() error {
return cli.api.ResourceServer.Delete(flags.ID)
})

if err != nil {
return err
}

return nil
},
}

Expand Down
40 changes: 19 additions & 21 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/auth0"
"github.com/auth0/auth0-cli/internal/prompt"
"github.com/spf13/cobra"
"gopkg.in/auth0.v5/management"
)
Expand All @@ -28,7 +29,7 @@ func appsCmd(cli *cli) *cobra.Command {
cmd.SetUsageTemplate(resourceUsageTemplate())
cmd.AddCommand(appsListCmd(cli))
cmd.AddCommand(appsCreateCmd(cli))
cmd.AddCommand(appsDeleteCmd(cli))
cmd.AddCommand(deleteAppCmd(cli))

return cmd
}
Expand Down Expand Up @@ -62,47 +63,44 @@ Lists your existing applications. To create one try:
return cmd
}

func appsDeleteCmd(cli *cli) *cobra.Command {
func deleteAppCmd(cli *cli) *cobra.Command {
var flags struct {
AppID string
ID string
}

cmd := &cobra.Command{
Use: "delete",
Short: "Delete an application",
Long: `Delete an application:
auth0 apps delete --id id
`,
PreRun: func(cmd *cobra.Command, args []string) {
prepareInteractivity(cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
if shouldPrompt(cmd, appID) {
input := prompt.TextInput(appID, "Id:", "Id of the application.", true)

if !cmd.Flags().Changed("id") {
qs := []*survey.Question{
{
Name: "AppID",
Prompt: &survey.Input{
Message: "AppID:",
Default: "My App",
Help: "ID of the application to delete.",
},
},
}

err := survey.Ask(qs, &flags)
if err != nil {
if err := prompt.AskOne(input, &flags); err != nil {
return err
}
}
c := &management.Client{
ClientID: &flags.AppID,

if !cli.force && canPrompt(cmd) {
if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed {
return nil
}
}

return ansi.Spinner("Deleting application", func() error {
return cli.api.Client.Delete(*c.ClientID)
return cli.api.Client.Delete(flags.ID)
})
},
}

cmd.Flags().StringVarP(&flags.AppID, "id", "i", "", "Id of the app.")
cmd.Flags().StringVarP(&flags.ID, appID, "i", "", "ID of the application.")
mustRequireFlags(cmd, appID)

return cmd
}
Expand Down

0 comments on commit b1990b1

Please sign in to comment.