Skip to content

Commit

Permalink
Add cobra.NoArgs to commands that don't take args
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket committed Apr 2, 2021
1 parent b92bd2d commit 5a2bfab
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Creating application... done
CLIENT SECRET QXV0aDAgaXMgaGlyaW5nISBhdXRoMC5jb20vY2FyZWVycyAK

▸ Quickstarts: https://auth0.com/docs/quickstart/webapp
▸ Hint: You might wanna try 'auth0 test login --client-id vXAtoaFdhlmtWjpIrjb9AUnrGEAOH2MM'
▸ Hint: You might wanna try 'auth0 test login vXAtoaFdhlmtWjpIrjb9AUnrGEAOH2MM'
```

As you might observe, the next thing to do would likely be to try logging in
Expand Down
22 changes: 12 additions & 10 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ func scopesCmd(cli *cli) *cobra.Command {

func listApisCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Use: "list",
Aliases: []string{"ls"},
Short: "List your APIs",
Args: cobra.NoArgs,
Short: "List your APIs",
Long: `auth0 apis list
Lists your existing APIs. To create one try:
auth0 apis create
Expand Down Expand Up @@ -108,7 +109,7 @@ func showApiCmd(cli *cli) *cobra.Command {
Use: "show",
Args: cobra.MaximumNArgs(1),
Short: "Show an API",
Long: `Show an API:`,
Long: `Show an API:`,
Example: `auth0 apis show
auth0 apis show <id>`,
PreRun: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -151,8 +152,9 @@ func createApiCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "create",
Args: cobra.NoArgs,
Short: "Create a new API",
Long: `Create a new API`,
Long: `Create a new API`,
Example: `auth0 apis create
auth0 apis create --name myapi
auth0 apis create -n myapi --identifier http://my-api
Expand Down Expand Up @@ -211,7 +213,7 @@ func updateApiCmd(cli *cli) *cobra.Command {
Use: "update",
Args: cobra.MaximumNArgs(1),
Short: "Update an API",
Long: `Update an API:`,
Long: `Update an API:`,
Example: `auth0 apis update
auth0 apis update <id>
auth0 apis update <id> --name myapi`,
Expand Down Expand Up @@ -286,7 +288,7 @@ func deleteApiCmd(cli *cli) *cobra.Command {
Use: "delete",
Args: cobra.MaximumNArgs(1),
Short: "Delete an API",
Long: `Delete an API:`,
Long: `Delete an API:`,
Example: `auth0 apis delete
auth0 apis delete <id>`,
PreRun: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -327,11 +329,11 @@ func listScopesCmd(cli *cli) *cobra.Command {
}

cmd := &cobra.Command{
Use: "list",
Use: "list",
Aliases: []string{"ls"},
Args: cobra.MaximumNArgs(1),
Short: "List the scopes of an API",
Long: `List the scopes of an API`,
Args: cobra.MaximumNArgs(1),
Short: "List the scopes of an API",
Long: `List the scopes of an API`,
Example: `auth0 apis scopes list
auth0 apis scopes ls <id>`,
PreRun: func(cmd *cobra.Command, args []string) {
Expand Down
23 changes: 13 additions & 10 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ func useAppCmd(cli *cli) *cobra.Command {
}

cmd := &cobra.Command{
Use: "use",
Short: "Choose a default application for the Auth0 CLI",
Long: `Specify your preferred application for interaction with the Auth0 CLI`,
Use: "use",
Args: cobra.MaximumNArgs(1),
Short: "Choose a default application for the Auth0 CLI",
Long: `Specify your preferred application for interaction with the Auth0 CLI`,
Example: `auth0 apps use <client-id>`,
PreRun: func(cmd *cobra.Command, args []string) {
prepareInteractivity(cmd)
Expand Down Expand Up @@ -182,12 +183,13 @@ func useAppCmd(cli *cli) *cobra.Command {

func listAppsCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Use: "list",
Aliases: []string{"ls"},
Short: "List your applications",
Args: cobra.NoArgs,
Short: "List your applications",
Long: `Lists your existing applications. To create one try:
auth0 apps create`,
Example: `auth0 apps list
Example: `auth0 apps list
auth0 apps ls`,
RunE: func(cmd *cobra.Command, args []string) error {
var list *management.ClientList
Expand Down Expand Up @@ -217,7 +219,7 @@ func showAppCmd(cli *cli) *cobra.Command {
Use: "show",
Args: cobra.MaximumNArgs(1),
Short: "Show an application",
Long: `Show an application:`,
Long: `Show an application:`,
Example: `auth0 apps show
auth0 apps show <id>`,
PreRun: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -261,7 +263,7 @@ func deleteAppCmd(cli *cli) *cobra.Command {
Use: "delete",
Args: cobra.MaximumNArgs(1),
Short: "Delete an application",
Long: `Delete an application:`,
Long: `Delete an application:`,
Example: `auth0 apps delete
auth0 apps delete <id>`,
PreRun: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -309,8 +311,9 @@ func createAppCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "create",
Args: cobra.NoArgs,
Short: "Create a new application",
Long: `Create a new application:`,
Long: `Create a new application:`,
Example: `auth0 apps create
auth0 apps create --name myapp
auth0 apps create -n myapp --type [native|spa|regular|m2m]
Expand Down Expand Up @@ -460,7 +463,7 @@ func updateAppCmd(cli *cli) *cobra.Command {
Use: "update",
Args: cobra.MaximumNArgs(1),
Short: "Update an application",
Long: `Update an application`,
Long: `Update an application`,
Example: `auth0 apps update <id>
auth0 apps update <id> --name myapp
auth0 apps update <id> -n myapp --type [native|spa|regular|m2m]`,
Expand Down
1 change: 1 addition & 0 deletions internal/cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
func loginCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Args: cobra.NoArgs,
Short: "Authenticate the Auth0 CLI",
Long: "sign in to your Auth0 account and authorize the CLI to access the API",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
func logoutCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "logout",
Args: cobra.MaximumNArgs(1),
Short: "Logout of a tenant's session",
Long: `auth0 logout <tenant>`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// NOTE(cyx): This was mostly copy/pasted from tenants
// use command. Consider refactoring.
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func listRulesCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Args: cobra.NoArgs,
Short: "List your rules",
Long: `List the rules in your current tenant.`,
Example: `auth0 rules list
Expand Down Expand Up @@ -105,6 +106,7 @@ func createRuleCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "create",
Args: cobra.NoArgs,
Short: "Create a new rule",
Long: `Create a new rule:`,
Example: `auth0 rules create
Expand Down Expand Up @@ -215,6 +217,7 @@ func deleteRuleCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "delete",
Args: cobra.MaximumNArgs(1),
Short: "Delete a rule",
Long: `Delete a rule`,
Example: `auth0 rules delete
Expand Down Expand Up @@ -256,6 +259,7 @@ func updateRuleCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "update",
Args: cobra.MaximumNArgs(1),
Short: "Update a rule",
Long: `Update a rule`,
Example: `auth0 rules update <rule-id>
Expand Down
12 changes: 6 additions & 6 deletions internal/cli/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func tenantsCmd(cli *cli) *cobra.Command {
func listTenantCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Args: cobra.NoArgs,
Short: "List your tenants",
Long: `auth0 tenants list`,
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
tens, err := cli.listTenants()
if err != nil {
Expand All @@ -45,11 +46,10 @@ func listTenantCmd(cli *cli) *cobra.Command {

func useTenantCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "use",
Aliases: []string{"select"},
Short: "Set the active tenant",
Long: `auth0 tenants use <tenant>`,
Args: cobra.MaximumNArgs(1),
Use: "use",
Args: cobra.MaximumNArgs(1),
Short: "Set the active tenant",
Long: `auth0 tenants use <tenant>`,
PreRun: func(cmd *cobra.Command, args []string) {
prepareInteractivity(cmd)
},
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ func testLoginCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "login",
Args: cobra.MaximumNArgs(1),
Short: "Try out your universal login box",
Long: `Launch a browser to try out your universal login box.
If --client-id is not provided, the default client "CLI Login Testing" will be used (and created if not exists.)`,
Long: `Launch a browser to try out your universal login box.`,
Example: `auth0 test login
auth0 test login --client-id <id>
auth0 test login -c <id> --connection <connection>`,
Args: cobra.MaximumNArgs(1),
auth0 test login <client-id>
auth0 test login <client-id> --connection <connection>`,
RunE: func(cmd *cobra.Command, args []string) error {
const commandKey = "test_login"
var userInfo *authutil.UserInfo
Expand Down Expand Up @@ -184,6 +183,7 @@ func testTokenCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "token",
Args: cobra.NoArgs,
Short: "Fetch a token for the given client and API",
Long: `Fetch an access token for the given client.
If --client-id is not provided, the default client "CLI Login Testing" will be used (and created if not exists).
Expand Down
2 changes: 1 addition & 1 deletion internal/display/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (r *Renderer) ApplicationCreate(client *management.Client, revealSecrets bo
r.Infof("Quickstarts: %s", quickstartsURIFor(client.AppType))

// TODO(cyx): possibly guard this with a --no-hint flag.
r.Infof("%s Test this app's login box with 'auth0 test login --client-id %s'",
r.Infof("%s Test this app's login box with 'auth0 test login %s'",
ansi.Faint("Hint:"),
client.GetClientID(),
)
Expand Down

0 comments on commit 5a2bfab

Please sign in to comment.