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

Empty array stdout with --json flag #747

Merged
merged 14 commits into from
Apr 20, 2023
Merged
4 changes: 4 additions & 0 deletions internal/display/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (r *Renderer) ActionList(actions []*management.Action) {
r.Heading(resource)

if len(actions) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 actions create' to add one")
return
Expand Down
8 changes: 8 additions & 0 deletions internal/display/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (r *Renderer) APIList(apis []*management.ResourceServer) {
r.Heading(fmt.Sprintf("%s (%d)", resource, len(apis)))

if len(apis) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 apis create' to add one")
return
Expand Down Expand Up @@ -161,6 +165,10 @@ func (r *Renderer) ScopesList(api string, scopes []management.ResourceServerScop
r.Heading(fmt.Sprintf("%s of %s", resource, ansi.Bold(api)))

if len(scopes) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
return
}
Expand Down
4 changes: 4 additions & 0 deletions internal/display/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func (r *Renderer) ApplicationList(clients []*management.Client, revealSecrets b
r.Heading(fmt.Sprintf("%s (%v)", resource, len(clients)))

if len(clients) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 apps create' to add one")
return
Expand Down
4 changes: 4 additions & 0 deletions internal/display/custom_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (r *Renderer) CustomDomainList(customDomains []*management.CustomDomain) {
r.Heading(resource)

if len(customDomains) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 domains create' to add one")
return
Expand Down
4 changes: 4 additions & 0 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (r *Renderer) Heading(text ...string) {
}

func (r *Renderer) EmptyState(resource string) {
if r.Format == OutputFormatJSON {
willvedd marked this conversation as resolved.
Show resolved Hide resolved
r.JSONResult([]interface{}{})
return
}
fmt.Fprintf(r.MessageWriter, "No %s available.\n\n", resource)
}

Expand Down
4 changes: 4 additions & 0 deletions internal/display/log_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (r *Renderer) LogStreamList(logs []*management.LogStream) {
r.Heading(resource)

if len(logs) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
willvedd marked this conversation as resolved.
Show resolved Hide resolved
r.EmptyState(resource)
r.Infof("Use 'auth0 logs streams create' to add one")
return
Expand Down
4 changes: 4 additions & 0 deletions internal/display/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func (r *Renderer) LogList(logs []*management.Log, silent, hasFilter bool) {
r.Heading(resource)

if len(logs) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:

if len(logs) == 0 {
	if !hasFilter {
		r.EmptyState(resource, "To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'")
		return
	}
	
	r.EmptyState("logs matching filter criteria", "")
	return
}

Like this it will print "No logs matching filter criteria available." and we have less complex code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO that reads very poorly. I'm glad we were able to reduce a couple one-off instances, but I think this one still makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Both sentences are grammatically correct and convey the same meaning 🤷🏻‍♂️ Not a blocker tho.

if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
if hasFilter {
r.Output("No logs available matching filter criteria.\n\n")
} else {
Expand Down
4 changes: 4 additions & 0 deletions internal/display/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (r *Renderer) OrganizationList(organizations []*management.Organization) {
r.Heading(resource)

if len(organizations) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 orgs create' to add one")
return
Expand Down
4 changes: 4 additions & 0 deletions internal/display/role_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (r *Renderer) RolePermissionList(perms []*management.Permission) {
r.Heading(resource)

if len(perms) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 roles permissions add' to add one")
return
Expand Down
10 changes: 9 additions & 1 deletion internal/display/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (r *Renderer) RoleList(roles []*management.Role) {
r.Heading(fmt.Sprintf("%s (%d)", resource, len(roles)))

if len(roles) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 roles create' to add one")
return
Expand All @@ -63,7 +67,11 @@ func (r *Renderer) UserRoleList(roles []*management.Role) {
r.Heading(fmt.Sprintf("%s (%d)", resource, len(roles)))

if len(roles) == 0 {
r.Output("No roles assigned to user.\n\n")
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
fmt.Fprintf(r.MessageWriter, "No %s.\n\n", resource)
willvedd marked this conversation as resolved.
Show resolved Hide resolved
r.Infof("Use 'auth0 users roles assign' to assign roles to a user.")
return
}
Expand Down
4 changes: 4 additions & 0 deletions internal/display/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (r *Renderer) RulesList(rules []*management.Rule) {
r.Heading(resource)

if len(rules) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 rules create' to add one")
return
Expand Down
4 changes: 4 additions & 0 deletions internal/display/user_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (r *Renderer) UserBlocksList(userBlocks []*management.UserBlock) {
r.Heading(resource)

if len(userBlocks) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
return
}
Expand Down
4 changes: 4 additions & 0 deletions internal/display/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (r *Renderer) UserSearch(users []*management.User) {
r.Heading(resource)

if len(users) == 0 {
if r.Format == OutputFormatJSON {
r.JSONResult([]interface{}{})
return
}
r.EmptyState(resource)
r.Infof("Use 'auth0 users create' to add one")
return
Expand Down
24 changes: 15 additions & 9 deletions test/integration/actions-test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ tests:
contains:
- Use 'auth0 actions create' to add one

002 - it successfully creates an action:
002 - it successfully lists all actions with no data (json):
command: auth0 actions list --json
exit-code: 0
stdout:
exactly: "[]"

003 - it successfully creates an action:
command: auth0 actions create -n "integration-test-action1" -t "post-login" -c "function() {}" -d "lodash=4.0.0" -s "SECRET=value"
exit-code: 0
stdout:
Expand All @@ -24,7 +30,7 @@ tests:
- "CREATED 0 seconds ago"
- "CODE function() {}"

003 - it successfully lists all actions with data:
004 - it successfully lists all actions with data:
command: auth0 actions list
exit-code: 0
stdout:
Expand All @@ -35,7 +41,7 @@ tests:
- STATUS
- DEPLOYED

004 - it successfully creates an action and outputs in json:
005 - it successfully creates an action and outputs in json:
command: auth0 actions create -n "integration-test-action2" -t "post-login" -c "function() {}" -d "lodash=4.0.0" -s "SECRET=value" --json
exit-code: 0
stdout:
Expand All @@ -50,7 +56,7 @@ tests:
secrets.0.value: "value"
status: "pending"

005 - given a test action, it successfully gets the action's details:
006 - given a test action, it successfully gets the action's details:
command: auth0 actions show $(./test/integration/scripts/get-action-id.sh)
exit-code: 0
stdout:
Expand All @@ -64,7 +70,7 @@ tests:
- "CREATED"
- "CODE function() {}"

006 - given a test action, it successfully gets the action's details and outputs in json:
007 - given a test action, it successfully gets the action's details and outputs in json:
command: auth0 actions show $(./test/integration/scripts/get-action-id.sh) --json
exit-code: 0
stdout:
Expand All @@ -77,7 +83,7 @@ tests:
dependencies.0.version: "4.0.0"
secrets.0.name: "SECRET"

007 - given a test action, it successfully updates the action's details:
008 - given a test action, it successfully updates the action's details:
command: auth0 actions update $(./test/integration/scripts/get-action-id.sh) -n "integration-test-action-updated" -c "function() {console.log()}" -d "uuid=9.0.0" -s "SECRET2=newValue"
exit-code: 0
stdout:
Expand All @@ -91,7 +97,7 @@ tests:
- "CREATED"
- "CODE function() {console.log()}"

008 - given a test action, it successfully updates the action's details and outputs in json:
009 - given a test action, it successfully updates the action's details and outputs in json:
command: auth0 actions update $(./test/integration/scripts/get-action-id.sh) -n "integration-test-action-updated-again" -c "function() {console.log()}" -d "uuid=9.0.0" -s "SECRET3=newValue" --json
exit-code: 0
stdout:
Expand All @@ -105,13 +111,13 @@ tests:
secrets.0.name: "SECRET3"
secrets.0.value: "newValue"

009 - given a test action, it successfully opens the settings page:
010 - given a test action, it successfully opens the settings page:
command: auth0 actions open $(./test/integration/scripts/get-action-id.sh) --no-input
exit-code: 0
stderr:
contains:
- "Open the following URL in a browser"

010 - given a test action, it successfully deletes the action:
011 - given a test action, it successfully deletes the action:
command: auth0 actions delete $(./test/integration/scripts/get-action-id.sh) --force
exit-code: 0
45 changes: 36 additions & 9 deletions test/integration/custom-domains-test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ config:
retries: 1

tests:
001 - list domains:
001 - list domains with no results:
command: auth0 domains list
exit-code: 0
002 - create domain with minimal flags:
stderr:
contains:
- No custom domains available.
- Use 'auth0 domains create' to add one

002 - list domains with no results (json):
command: auth0 domains list --json
exit-code: 0
stdout:
exactly: "[]"

003 - create domain with minimal flags:
command: auth0 domains create --domain "custom-domain.com" --no-input
exit-code: 0
stdout:
Expand All @@ -15,13 +26,15 @@ tests:
- "DOMAIN custom-domain.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
003 - unsuccessfully create domain with same name:

004 - unsuccessfully create domain with same name:
command: auth0 domains create --domain "custom-domain.com" --no-input
exit-code: 1
stderr:
contains:
- "An unexpected error occurred while attempting to create the custom domain 'custom-domain.com': 409 Conflict: The specified custom domain already exists"
004 - show domain:

005 - show domain:
command: auth0 domains show $(./test/integration/scripts/get-custom-domain-id.sh) --no-input
exit-code: 0
stdout:
Expand All @@ -30,7 +43,8 @@ tests:
- "DOMAIN custom-domain.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
005 - update domain minimal flags:

006 - update domain minimal flags:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --no-input
exit-code: 0
stdout:
Expand All @@ -39,7 +53,8 @@ tests:
- "DOMAIN custom-domain.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
006 - update domain maximal flags:

007 - update domain maximal flags:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --policy recommended --no-input
exit-code: 0
stdout:
Expand All @@ -49,7 +64,8 @@ tests:
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
- "TLS POLICY recommended"
007 - verify domain:

008 - verify domain:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --policy recommended --no-input
exit-code: 0
stdout:
Expand All @@ -58,10 +74,12 @@ tests:
- "DOMAIN custom-domain.com"
- "PROVISIONING TYPE auth0_managed_certs"
- "TLS POLICY recommended"
008 - delete domain:

009 - delete domain:
command: auth0 domains delete $(./test/integration/scripts/get-custom-domain-id.sh) --no-input
exit-code: 0
009 - create domain with maximal flags:

010 - create domain with maximal flags:
command: auth0 domains create --domain "custom-domain.com" --verification txt --type self --policy recommended --no-input
exit-code: 0
stdout:
Expand All @@ -73,3 +91,12 @@ tests:
- "VERIFICATION METHOD txt"
- "TLS POLICY recommended"
- "CUSTOM CLIENT IP HEADER"

011 - list custom domains with results:
command: auth0 domains list
exit-code: 0
stdout:
contains:
- "ID DOMAIN STATUS"
- "cd_"
- "custom-domain.com"
Loading