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

DXCDT-326: align --number usage across commands #610

Merged
merged 8 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
From the top-level directory:
```
$ make build
$ ./auth0 --help
$ ./out/auth0 --help
```

## Adding a new command
Expand Down Expand Up @@ -41,7 +41,7 @@ We use vendoring, so the last step is required.

> This is only possible if you're a repository maintainer.

The release is driven by a Github **workflow** triggered when a new **tag** is **created**. The workflow will run the checks and trigger _Goreleaser_ to:
The release is driven by a GitHub **workflow** triggered when a new **tag** is **created**. The workflow will run the checks and trigger _Goreleaser_ to:
- create the Release with the proper description (changelog)
- upload the binaries for the different architectures
- update https://github.com/auth0/homebrew-auth0-cli with the latest binary reference
Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_apis_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ auth0 apis list [flags]

```
--json Output in json format.
-n, --number int Number of apps to retrieve (default 50)
-n, --number int Number of APIs to retrieve. Minimum 1, maximum 1000. (default 50)
```


Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_apps_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ auth0 apps list [flags]

```
--json Output in json format.
-n, --number int Number of apps to retrieve (default 50)
-n, --number int Number of apps to retrieve. Minimum 1, maximum 1000. (default 50)
-r, --reveal-secrets Display the application secrets ('signing_keys', 'client_secret') as part of the command output.
```

Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_orgs_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ auth0 orgs list [flags]

```
--json Output in json format.
-n, --number int Number of apps to retrieve (default 50)
-n, --number int Number of organizations to retrieve. Minimum 1, maximum 1000. (default 50)
```


Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_orgs_members_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ auth0 orgs members list [flags]

```
--json Output in json format.
-n, --number int Number of apps to retrieve (default 50)
-n, --number int Number of organization members to retrieve. Minimum 1, maximum 1000. (default 50)
```


Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_orgs_roles_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ auth0 orgs roles list [flags]

```
--json Output in json format.
-n, --number int Number of apps to retrieve (default 50)
-n, --number int Number of organization roles to retrieve. Minimum 1, maximum 1000. (default 50)
```


Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_orgs_roles_members_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ auth0 orgs roles members list [flags]

```
--json Output in json format.
-n, --number int Number of apps to retrieve (default 50)
-n, --number int Number of members to retrieve. Minimum 1, maximum 1000. (default 50)
-r, --role-id string Role Identifier.
```

Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_roles_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ auth0 roles list [flags]

```
--json Output in json format.
-n, --number int Number of apps to retrieve (default 50)
-n, --number int Number of roles to retrieve. Minimum 1, maximum 1000. (default 50)
```


Expand Down
6 changes: 4 additions & 2 deletions docs/auth0_roles_permissions_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ auth0 roles permissions list [flags]
```
auth0 roles permissions list
auth0 roles permissions ls <role-id>
auth0 roles permissions ls <role-id> --json
auth0 roles permissions ls <role-id> --number 100
auth0 roles permissions ls <role-id> -n 100 --json
```


## Flags

```
--json Output in json format.
--json Output in json format.
-n, --number int Number of permissions to retrieve. Minimum 1, maximum 1000. (default 50)
```


Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_users_search.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ auth0 users search [flags]

```
--json Output in json format.
-n, --number int Number of users, that match the search criteria, to retrieve. Maximum result number is 1000. If limit is hit, please refine the search query. (default 50)
-n, --number int Number of users, that match the search criteria, to retrieve. Minimum 1, maximum 1000. If limit is hit, refine the search query. (default 50)
-q, --query string Query in Lucene query syntax. See https://auth0.com/docs/users/user-search/user-search-query-syntax for more details.
-s, --sort string Field to sort by. Use 'field:order' where 'order' is '1' for ascending and '-1' for descending. e.g. 'created_at:1'.
```
Expand Down
2 changes: 1 addition & 1 deletion internal/ansi/ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Color() aurora.Aurora {

// Initialize re-instantiates the Aurora instance
// This initialization step is necessary because the parsing of the
// --no-color flag is done fairly late in the application cycle
// --no-color flag is done fairly late in the application cycle.
func Initialize(shouldDisableColors bool) {
DisableColors = shouldDisableColors
color = Color()
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ var (
Help: "Whether Refresh Tokens can be issued for this API (true) or not (false).",
AlwaysPrompt: true,
}
apiNumber = Flag{
Name: "Number",
LongForm: "number",
ShortForm: "n",
Help: "Number of APIs to retrieve. Minimum 1, maximum 1000.",
}
)

func apisCmd(cli *cli) *cobra.Command {
Expand Down Expand Up @@ -107,6 +113,10 @@ func listApisCmd(cli *cli) *cobra.Command {
auth0 apis ls --number 100
auth0 apis ls -n 100 --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if inputs.Number < 1 || inputs.Number > 1000 {
return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000")
}

list, err := getWithPagination(
cmd.Context(),
inputs.Number,
Expand Down Expand Up @@ -139,7 +149,7 @@ func listApisCmd(cli *cli) *cobra.Command {
}

cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
number.RegisterInt(cmd, &inputs.Number, defaultPageSize)
apiNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize)

return cmd
}
Expand Down
10 changes: 7 additions & 3 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ var (
ShortForm: "r",
Help: "Display the application secrets ('signing_keys', 'client_secret') as part of the command output.",
}
number = Flag{
appNumber = Flag{
Name: "Number",
LongForm: "number",
ShortForm: "n",
Help: "Number of apps to retrieve",
Help: "Number of apps to retrieve. Minimum 1, maximum 1000.",
}
)

Expand Down Expand Up @@ -216,6 +216,10 @@ func listAppsCmd(cli *cli) *cobra.Command {
auth0 apps list --reveal-secrets --number 100
auth0 apps ls -r -n 100 --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if inputs.Number < 1 || inputs.Number > 1000 {
return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000")
}

list, err := getWithPagination(
cmd.Context(),
inputs.Number,
Expand Down Expand Up @@ -244,7 +248,7 @@ func listAppsCmd(cli *cli) *cobra.Command {

cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
revealSecrets.RegisterBool(cmd, &inputs.RevealSecrets, false)
number.RegisterInt(cmd, &inputs.Number, defaultPageSize)
appNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize)

return cmd
}
Expand Down
34 changes: 30 additions & 4 deletions internal/cli/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ var (
Help: "Role Identifier.",
IsRequired: true,
}

// Purposefully not setting the Help value on the Flag because overridden where appropriate.
organizationNumber = Flag{
Name: "Number",
LongForm: "number",
ShortForm: "n",
}
)

func organizationsCmd(cli *cli) *cobra.Command {
Expand Down Expand Up @@ -117,6 +124,10 @@ func listOrganizationsCmd(cli *cli) *cobra.Command {
auth0 orgs ls --json
auth0 orgs ls -n 100`,
RunE: func(cmd *cobra.Command, args []string) error {
if inputs.Number < 1 || inputs.Number > 1000 {
return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000")
}

list, err := getWithPagination(
cmd.Context(),
inputs.Number,
Expand Down Expand Up @@ -149,7 +160,8 @@ func listOrganizationsCmd(cli *cli) *cobra.Command {
}

cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
number.RegisterInt(cmd, &inputs.Number, defaultPageSize)
organizationNumber.Help = "Number of organizations to retrieve. Minimum 1, maximum 1000."
organizationNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize)

return cmd
}
Expand Down Expand Up @@ -507,6 +519,10 @@ func listMembersOrganizationCmd(cli *cli) *cobra.Command {
auth0 orgs members list <org-id> --number 100
auth0 orgs members ls <org-id> -n 100 --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if inputs.Number < 1 || inputs.Number > 1000 {
return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000")
}

if len(args) == 0 {
err := organizationID.Pick(cmd, &inputs.ID, cli.organizationPickerOptions)
if err != nil {
Expand All @@ -526,7 +542,8 @@ func listMembersOrganizationCmd(cli *cli) *cobra.Command {
},
}

number.RegisterInt(cmd, &inputs.Number, defaultPageSize)
organizationNumber.Help = "Number of organization members to retrieve. Minimum 1, maximum 1000."
organizationNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize)
cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
cmd.SetUsageTemplate(resourceUsageTemplate())

Expand Down Expand Up @@ -565,6 +582,9 @@ func listRolesOrganizationCmd(cli *cli) *cobra.Command {
auth0 orgs roles list <org-id> --number 100
auth0 orgs roles ls <org-id> -n 100 --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if inputs.Number < 1 || inputs.Number > 1000 {
return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000")
}
if len(args) == 0 {
err := organizationID.Pick(cmd, &inputs.OrgID, cli.organizationPickerOptions)
if err != nil {
Expand All @@ -588,7 +608,8 @@ func listRolesOrganizationCmd(cli *cli) *cobra.Command {
},
}

number.RegisterInt(cmd, &inputs.Number, defaultPageSize)
organizationNumber.Help = "Number of organization roles to retrieve. Minimum 1, maximum 1000."
organizationNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize)

cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")

Expand Down Expand Up @@ -628,6 +649,10 @@ func listMembersRolesOrganizationCmd(cli *cli) *cobra.Command {
auth0 orgs roles members ls <org-id> -r role -n 100
auth0 orgs roles members ls <org-id> -r role -n 100 --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if inputs.Number < 1 || inputs.Number > 1000 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine that you considered separating this into its own separate function. Was the idea here to keep the overhead low?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't consider moving this validation out, but @sergiught and I did chat about whether we could add a way to provide validation within a Flag struct rather than have the validation logic within the command logic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whether we could add a way to provide validation within a Flag struct rather than have the validation logic within the command logic

Good idea!

Copy link
Contributor

@sergiught sergiught Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Wdyt if we keep the current number validation in this PR to keep things simple, even tho repeated, and follow up with a PR to add a Validation field on the Flag struct?

return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000")
}

if len(args) == 0 {
err := organizationID.Pick(cmd, &inputs.OrgID, cli.organizationPickerOptions)
if err != nil {
Expand Down Expand Up @@ -661,7 +686,8 @@ func listMembersRolesOrganizationCmd(cli *cli) *cobra.Command {
cmd.SetUsageTemplate(resourceUsageTemplate())
cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
roleIdentifier.RegisterString(cmd, &inputs.RoleID, "")
number.RegisterInt(cmd, &inputs.Number, defaultPageSize)
organizationNumber.Help = "Number of members to retrieve. Minimum 1, maximum 1000."
organizationNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize)

return cmd
}
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ var (
ShortForm: "d",
Help: "Description of the role.",
}
roleNumber = Flag{
Name: "Number",
LongForm: "number",
ShortForm: "n",
Help: "Number of roles to retrieve. Minimum 1, maximum 1000.",
}
)

func rolesCmd(cli *cli) *cobra.Command {
Expand Down Expand Up @@ -66,6 +72,10 @@ func listRolesCmd(cli *cli) *cobra.Command {
auth0 roles ls --number 100
auth0 roles ls -n 100 --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if inputs.Number < 1 || inputs.Number > 1000 {
return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000")
}

list, err := getWithPagination(
cmd.Context(),
inputs.Number,
Expand Down Expand Up @@ -98,7 +108,7 @@ func listRolesCmd(cli *cli) *cobra.Command {
}

cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
number.RegisterInt(cmd, &inputs.Number, defaultPageSize)
roleNumber.RegisterInt(cmd, &inputs.Number, defaultPageSize)

return cmd
}
Expand Down
Loading