Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli 6 #99

Merged
merged 6 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 63 additions & 16 deletions internal/cli/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,32 @@ import (
"gopkg.in/auth0.v5/management"
)

func clientsCmd(cli *cli) *cobra.Command {
func appsCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "clients",
Short: "Manage resources for clients",
Use: "apps",
Short: "Manage resources for apps",
}

cmd.SetUsageTemplate(resourceUsageTemplate())
cmd.AddCommand(clientsListCmd(cli))
cmd.AddCommand(clientsCreateCmd(cli))
cmd.AddCommand(appsListCmd(cli))
cmd.AddCommand(appsCreateCmd(cli))
cmd.AddCommand(appsDeleteCmd(cli))

return cmd
}

func clientsListCmd(cli *cli) *cobra.Command {
func appsListCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List your existing clients",
Long: `auth0 client list
Lists your existing clients. To create one try:
Short: "List your existing apps",
Long: `auth0 app list
bright-poku marked this conversation as resolved.
Show resolved Hide resolved
Lists your existing apps. To create one try:

auth0 clients create
auth0 apps create
`,
RunE: func(cmd *cobra.Command, args []string) error {
var list *management.ClientList
err := ansi.Spinner("Loading clients", func() error {
err := ansi.Spinner("Loading apps", func() error {
var err error
list, err = cli.api.Client.List()
return err
Expand All @@ -53,7 +54,53 @@ Lists your existing clients. To create one try:
return cmd
}

func clientsCreateCmd(cli *cli) *cobra.Command {
func appsDeleteCmd(cli *cli) *cobra.Command {
var flags struct {
AppID string
}
cmd := &cobra.Command{
Use: "delete",
Short: "Delete an existing app",
Long: `auth0 apps delete --name appName

auth0 apps delete --app-id myapp

`,
RunE: func(cmd *cobra.Command, args []string) error {

if !cmd.Flags().Changed("app-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 {
return err
}
}
c := &management.Client{
ClientID: &flags.AppID,
}

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

cmd.Flags().StringVarP(&flags.AppID, "app-id", "i", "", "app-id of the app.")

return cmd
}

func appsCreateCmd(cli *cli) *cobra.Command {
var flags struct {
Name string
AppType string
Expand All @@ -63,10 +110,10 @@ func clientsCreateCmd(cli *cli) *cobra.Command {
}
cmd := &cobra.Command{
Use: "create",
Short: "Create a new client (also know as application)",
Long: `Create a new client (or application):
Short: "Create a new application",
Long: `Create a new application:

auth0 clients create --name myapp --type [native|spa|regular|m2m]
auth0 apps create --name myapp --type [native|spa|regular|m2m]

- supported application type:
`,
Expand Down Expand Up @@ -155,7 +202,7 @@ auth0 clients create --name myapp --type [native|spa|regular|m2m]
"- regular: Traditional web app using redirects.\n"+
"- m2m (machine to machine): CLIs, daemons or services running on your backend.")
cmd.Flags().StringVarP(&flags.Description, "description", "d", "", "A free text description of the application. Max character count is 140.")
cmd.Flags().StringSliceVarP(&flags.Callbacks, "callbacks", "c", nil, "After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native clients, all callbacks should use protocol https://.")
cmd.Flags().StringSliceVarP(&flags.Callbacks, "callbacks", "c", nil, "After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native apps, all callbacks should use protocol https://.")

cmd.Flags().StringVar(&flags.TokenEndpointAuthMethod, "auth-method", "", "Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).")

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestClientsListCmd(t *testing.T) {
api: &auth0.API{Client: clientAPI},
}

cmd := clientsListCmd(cli)
cmd := appsListCmd(cli)

if err := cmd.Execute(); err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Execute() {
// so add new commands in a place that reflect its relevance or relation with other commands:
rootCmd.AddCommand(loginCmd(cli))
rootCmd.AddCommand(quickstartCmd(cli))
rootCmd.AddCommand(clientsCmd(cli))
rootCmd.AddCommand(appsCmd(cli))
rootCmd.AddCommand(apisCmd(cli))
rootCmd.AddCommand(tryLoginCmd(cli))
rootCmd.AddCommand(logsCmd(cli))
Expand Down