From 5620e50baf8e447db858380380b8842dff41edad Mon Sep 17 00:00:00 2001 From: Michael Christenson II Date: Thu, 21 Dec 2023 16:26:48 -0500 Subject: [PATCH] Dxcdt 393 ensure status and progress indicator (#949) * Bump github.com/auth0/go-auth0 from 1.2.0 to 1.3.0 (#908) Bumps [github.com/auth0/go-auth0](https://github.com/auth0/go-auth0) from 1.2.0 to 1.3.0. - [Release notes](https://github.com/auth0/go-auth0/releases) - [Changelog](https://github.com/auth0/go-auth0/blob/main/CHANGELOG.md) - [Commits](https://github.com/auth0/go-auth0/compare/v1.2.0...v1.3.0) --- updated-dependencies: - dependency-name: github.com/auth0/go-auth0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * dxcdt-615-goreleaser-upgrade (#909) * Fix: Remove or replace deprecations for GoReleaser config Remove deprecated replacements Replace deprecated brews tap Replace deprecated scoop entries Fix name_template to reflect exact current naming conventions * DXCDT-582: Convert audience into a drop down in interactive mode in test token cmd (#906) Convert audience into a drop down in interactive mode in test token cmd * Bump github.com/auth0/go-auth0 from 1.2.0 to 1.3.0 (#908) Bumps [github.com/auth0/go-auth0](https://github.com/auth0/go-auth0) from 1.2.0 to 1.3.0. - [Release notes](https://github.com/auth0/go-auth0/releases) - [Changelog](https://github.com/auth0/go-auth0/blob/main/CHANGELOG.md) - [Commits](https://github.com/auth0/go-auth0/compare/v1.2.0...v1.3.0) --- updated-dependencies: - dependency-name: github.com/auth0/go-auth0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] Co-authored-by: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * DXCDT-582: Convert audience into a drop down in interactive mode in test token cmd (#906) Convert audience into a drop down in interactive mode in test token cmd Title Os for final release name fit * Bump goreleaser version * Use progress bars for long multistep processes Create generic ProgressBar Ensure 1 or less items behaves like Spinner Add progress bars to possibly longer processes * Bump github.com/google/uuid from 1.4.0 to 1.5.0 (#942) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Dxcdt 578 increase results amount in lists (#940) * Bump github.com/auth0/go-auth0 from 1.2.0 to 1.3.0 (#908) Bumps [github.com/auth0/go-auth0](https://github.com/auth0/go-auth0) from 1.2.0 to 1.3.0. - [Release notes](https://github.com/auth0/go-auth0/releases) - [Changelog](https://github.com/auth0/go-auth0/blob/main/CHANGELOG.md) - [Commits](https://github.com/auth0/go-auth0/compare/v1.2.0...v1.3.0) --- updated-dependencies: - dependency-name: github.com/auth0/go-auth0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * dxcdt-615-goreleaser-upgrade (#909) * Fix: Remove or replace deprecations for GoReleaser config Remove deprecated replacements Replace deprecated brews tap Replace deprecated scoop entries Fix name_template to reflect exact current naming conventions * DXCDT-582: Convert audience into a drop down in interactive mode in test token cmd (#906) Convert audience into a drop down in interactive mode in test token cmd * Bump github.com/auth0/go-auth0 from 1.2.0 to 1.3.0 (#908) Bumps [github.com/auth0/go-auth0](https://github.com/auth0/go-auth0) from 1.2.0 to 1.3.0. - [Release notes](https://github.com/auth0/go-auth0/releases) - [Changelog](https://github.com/auth0/go-auth0/blob/main/CHANGELOG.md) - [Commits](https://github.com/auth0/go-auth0/compare/v1.2.0...v1.3.0) --- updated-dependencies: - dependency-name: github.com/auth0/go-auth0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] Co-authored-by: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * DXCDT-582: Convert audience into a drop down in interactive mode in test token cmd (#906) Convert audience into a drop down in interactive mode in test token cmd Title Os for final release name fit * Bump goreleaser version * Increase default page amount to 100 results per page * Updated docs for defalut list limit --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> * Bump github.com/auth0/go-auth0 from 1.3.1 to 1.4.0 (#944) * DXCDT-396: Standardize error messages (#943) * Bump golang.org/x/crypto from 0.16.0 to 0.17.0 (#947) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Ignore err for adding steps to the ProgressBar This is a specific error, internal to the developer and not of use to the user * Organize imports * Improve error messages in APIs * Add documentation comment for ProgressBar Co-authored-by: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> * Normalize delete error messages * Discard duplicate path escape * Revert data file * Return nil on 0 case * Ensure ID isn't empty when deleting an organization --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> --- go.mod | 4 +++- go.sum | 11 ++++++++- internal/ansi/progress.go | 29 ++++++++++++++++++++++ internal/auth/authutil/browser.go | 2 +- internal/auth/authutil/browser_test.go | 2 +- internal/cli/actions.go | 13 ++++------ internal/cli/apis.go | 22 +++++++---------- internal/cli/apps.go | 22 +++++++---------- internal/cli/custom_domains.go | 23 +++++++----------- internal/cli/log_streams.go | 21 +++++++--------- internal/cli/organizations.go | 23 +++++++----------- internal/cli/roles.go | 22 +++++++---------- internal/cli/rules.go | 22 +++++++---------- internal/cli/users.go | 22 +++++++---------- internal/cli/users_blocks.go | 33 +++++++++++--------------- internal/cli/utils_shared.go | 4 ++-- 16 files changed, 135 insertions(+), 140 deletions(-) create mode 100644 internal/ansi/progress.go diff --git a/go.mod b/go.mod index 59c747331..b0cae4e6d 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/olekukonko/tablewriter v0.0.5 github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 github.com/pkg/errors v0.9.1 + github.com/schollz/progressbar/v3 v3.14.1 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 @@ -76,12 +77,13 @@ require ( github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/microcosm-cc/bluemonday v1.0.23 // indirect + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.13.0 // indirect github.com/nwaples/rardecode v1.1.0 // indirect github.com/pierrec/lz4/v4 v4.1.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rivo/uniseg v0.2.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/ulikunitz/xz v0.5.10 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect github.com/yuin/goldmark v1.5.2 // indirect diff --git a/go.sum b/go.sum index d353bdb50..74cf0c70b 100644 --- a/go.sum +++ b/go.sum @@ -114,6 +114,7 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= @@ -171,6 +172,8 @@ github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssn github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= github.com/microcosm-cc/bluemonday v1.0.23 h1:SMZe2IGa0NuHvnVNAZ+6B38gsTbi5e4sViiWJyDDqFY= github.com/microcosm-cc/bluemonday v1.0.23/go.mod h1:mN70sk7UkkF8TUr2IGBpNN0jAgStuPzlK76QuruE/z4= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.13.0 h1:wK20DRpJdDX8b7Ek2QfhvqhRQFZ237RGRO0RQ/Iqdy0= @@ -193,11 +196,14 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/schollz/progressbar/v3 v3.14.1 h1:VD+MJPCr4s3wdhTc7OEJ/Z3dAeBzJ7yKH/P4lC5yRTI= +github.com/schollz/progressbar/v3 v3.14.1/go.mod h1:Zc9xXneTzWXF81TGoqL71u0sBPjULtEHYtj/WVgVy8E= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= @@ -210,6 +216,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -295,6 +302,7 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -303,6 +311,7 @@ golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/ansi/progress.go b/internal/ansi/progress.go new file mode 100644 index 000000000..7d85c0eec --- /dev/null +++ b/internal/ansi/progress.go @@ -0,0 +1,29 @@ +package ansi + +import ( + "errors" + + "github.com/schollz/progressbar/v3" +) + +// ProgressBar will display progress indication for the given items. +func ProgressBar[T comparable](desc string, items []T, fn func(int, T) error) error { + switch len(items) { + case 0: + return nil + case 1: + return Spinner(desc, func() error { + return fn(1, items[0]) + }) + default: + bar := progressbar.Default(int64(len(items)), desc) + var errs []error + for i, item := range items { + _ = bar.Add(1) + if err := fn(i, item); err != nil { + errs = append(errs, err) + } + } + return errors.Join(errs...) + } +} diff --git a/internal/auth/authutil/browser.go b/internal/auth/authutil/browser.go index 10e03b7ca..d470e307c 100644 --- a/internal/auth/authutil/browser.go +++ b/internal/auth/authutil/browser.go @@ -35,7 +35,7 @@ func WaitForBrowserCallback(addr string) (code string, state string, err error) if cb.code == "" { _, _ = w.Write([]byte(resultPage("Login Failed", - "Unable to extract code from request, please try authenticating again.", + "Failed to extract code from request, please try authenticating again.", "error-denied"))) } else { _, _ = w.Write([]byte(resultPage("Login Successful", diff --git a/internal/auth/authutil/browser_test.go b/internal/auth/authutil/browser_test.go index e8fc77622..d6fa39afc 100644 --- a/internal/auth/authutil/browser_test.go +++ b/internal/auth/authutil/browser_test.go @@ -49,7 +49,7 @@ func TestWaitForBrowserCallback(t *testing.T) { _ = resp.Body.Close() }() - assert.Contains(t, body, "Unable to extract code from request, please try authenticating again") + assert.Contains(t, body, "Failed to extract code from request, please try authenticating again") }) code, state, callbackErr := WaitForBrowserCallback("localhost:1234") diff --git a/internal/cli/actions.go b/internal/cli/actions.go index ad71d9378..c0c2f7e5c 100644 --- a/internal/cli/actions.go +++ b/internal/cli/actions.go @@ -391,16 +391,13 @@ func deleteActionCmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting action(s)", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if err := cli.api.Action.Delete(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete action with ID %q: %w", id, err)) - } + return ansi.ProgressBar("Deleting action(s)", ids, func(i int, id string) error { + if id != "" { + if err := cli.api.Action.Delete(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete Action with ID %q: %w", id, err) } } - return errors.Join(errs...) + return nil }) }, } diff --git a/internal/cli/apis.go b/internal/cli/apis.go index d8efaff63..9775fe79b 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -445,21 +445,15 @@ func deleteAPICmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting API(s)", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if _, err := cli.api.ResourceServer.Read(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete API with ID %q: %w", id, err)) - continue - } - - if err := cli.api.ResourceServer.Delete(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete API with ID %q: %w", id, err)) - } - } + return ansi.ProgressBar("Deleting API(s)", ids, func(_ int, id string) error { + if _, err := cli.api.ResourceServer.Read(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete API with ID %q: %w", id, err) + } + + if err := cli.api.ResourceServer.Delete(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete API with ID %q: %w", id, err) } - return errors.Join(errs...) + return nil }) }, } diff --git a/internal/cli/apps.go b/internal/cli/apps.go index 9567eb239..c60483378 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -347,21 +347,17 @@ func deleteAppCmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting Application(s)", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if _, err := cli.api.Client.Read(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete application with ID %q: %w", id, err)) - continue - } - - if err := cli.api.Client.Delete(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete application with ID %q: %w", id, err)) - } + return ansi.ProgressBar("Deleting Application(s)", ids, func(_ int, id string) error { + if id != "" { + if _, err := cli.api.Client.Read(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete application with ID %q: %w", id, err) + } + + if err := cli.api.Client.Delete(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete application with ID %q: %w", id, err) } } - return errors.Join(errs...) + return nil }) }, } diff --git a/internal/cli/custom_domains.go b/internal/cli/custom_domains.go index a46bb9bdf..d21f75b63 100644 --- a/internal/cli/custom_domains.go +++ b/internal/cli/custom_domains.go @@ -2,7 +2,6 @@ package cli import ( "context" - "errors" "fmt" "net/url" @@ -348,21 +347,17 @@ func deleteCustomDomainCmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting custom domain", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if _, err := cli.api.CustomDomain.Read(cmd.Context(), url.PathEscape(id)); err != nil { - return fmt.Errorf("failed to delete custom domain with ID %q: %w", id, err) - } - - if err := cli.api.CustomDomain.Delete(cmd.Context(), url.PathEscape(id)); err != nil { - return fmt.Errorf("failed to delete custom domain with ID %q: %w", id, err) - } + return ansi.ProgressBar("Deleting custom domain", ids, func(_ int, id string) error { + if id != "" { + if _, err := cli.api.CustomDomain.Read(cmd.Context(), url.PathEscape(id)); err != nil { + return fmt.Errorf("failed to delete custom domain with ID %q: %w", id, err) } - } - return errors.Join(errs...) + if err := cli.api.CustomDomain.Delete(cmd.Context(), url.PathEscape(id)); err != nil { + return fmt.Errorf("failed to delete custom domain with ID %q: %w", id, err) + } + } + return nil }) }, } diff --git a/internal/cli/log_streams.go b/internal/cli/log_streams.go index b8347e7e2..6fab1292f 100644 --- a/internal/cli/log_streams.go +++ b/internal/cli/log_streams.go @@ -199,21 +199,16 @@ func deleteLogStreamCmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting Log Stream(s)", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if _, err := cli.api.LogStream.Read(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete log stream with ID %q: %w", id, err)) - continue - } - if err := cli.api.LogStream.Delete(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete log stream with ID %q: %w", id, err)) - } + return ansi.ProgressBar("Deleting Log Stream(s)", ids, func(_ int, id string) error { + if id != "" { + if _, err := cli.api.LogStream.Read(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete log stream with ID %q: %w", id, err) + } + if err := cli.api.LogStream.Delete(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete log stream with ID %q: %w", id, err) } } - - return errors.Join(errs...) + return nil }) }, } diff --git a/internal/cli/organizations.go b/internal/cli/organizations.go index 69f38817d..275a70a91 100644 --- a/internal/cli/organizations.go +++ b/internal/cli/organizations.go @@ -437,21 +437,17 @@ func deleteOrganizationCmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting organization(s)", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if _, err := cli.api.Organization.Read(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete organization with ID %q: %w", id, err)) - continue - } - - if err := cli.api.Organization.Delete(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete organization with ID %q: %w", id, err)) - } + return ansi.ProgressBar("Deleting organization(s)", ids, func(_ int, id string) error { + if id != "" { + if _, err := cli.api.Organization.Read(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete organization with ID %q: %w", id, err) + } + + if err := cli.api.Organization.Delete(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete organization with ID %q: %w", id, err) } } - return errors.Join(errs...) + return nil }) }, } @@ -597,7 +593,6 @@ func listRolesOrganizationCmd(cli *cli) *cobra.Command { } else { inputs.OrgID = args[0] } - members, err := cli.getOrgMembersWithSpinner(cmd.Context(), inputs.OrgID, inputs.Number) if err != nil { return err diff --git a/internal/cli/roles.go b/internal/cli/roles.go index 779662230..b15c9dbcf 100644 --- a/internal/cli/roles.go +++ b/internal/cli/roles.go @@ -306,21 +306,17 @@ func deleteRoleCmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting Role(s)", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if _, err := cli.api.Role.Read(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete role with ID %q: %w", id, err)) - continue - } - - if err := cli.api.Role.Delete(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete role with ID %q: %w", id, err)) - } + return ansi.ProgressBar("Deleting Role(s)", ids, func(_ int, id string) error { + if id != "" { + if _, err := cli.api.Role.Read(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete role with ID %q: %w", id, err) + } + + if err := cli.api.Role.Delete(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete role with ID %q: %w", id, err) } } - return errors.Join(errs...) + return nil }) }, } diff --git a/internal/cli/rules.go b/internal/cli/rules.go index 0a9f170a1..046cd91ba 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -281,21 +281,17 @@ func deleteRuleCmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting Rule(s)", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if _, err := cli.api.Rule.Read(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete rule with ID %q: %w", id, err)) - continue - } - - if err := cli.api.Rule.Delete(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete rule with ID %q: %w", id, err)) - } + return ansi.ProgressBar("Deleting Rule(s)", ids, func(_ int, id string) error { + if id != "" { + if _, err := cli.api.Rule.Read(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete rule with ID %q: %w", id, err) + } + + if err := cli.api.Rule.Delete(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete rule with ID %q: %w", id, err) } } - return errors.Join(errs...) + return nil }) }, } diff --git a/internal/cli/users.go b/internal/cli/users.go index d561b0eed..a0498e21b 100644 --- a/internal/cli/users.go +++ b/internal/cli/users.go @@ -392,21 +392,17 @@ func deleteUserCmd(cli *cli) *cobra.Command { } } - return ansi.Spinner("Deleting user(s)", func() error { - var errs []error - for _, id := range ids { - if id != "" { - if _, err := cli.api.User.Read(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete user with ID %q: %w", id, err)) - continue - } - - if err := cli.api.User.Delete(cmd.Context(), id); err != nil { - errs = append(errs, fmt.Errorf("failed to delete user with ID %q: %w", id, err)) - } + return ansi.ProgressBar("Deleting user(s)", ids, func(_ int, id string) error { + if id != "" { + if _, err := cli.api.User.Read(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete user with ID %q: %w", id, err) + } + + if err := cli.api.User.Delete(cmd.Context(), id); err != nil { + return fmt.Errorf("failed to delete user with ID %q: %w", id, err) } } - return errors.Join(errs...) + return nil }) }, } diff --git a/internal/cli/users_blocks.go b/internal/cli/users_blocks.go index 0e57702bf..e338b2ae0 100644 --- a/internal/cli/users_blocks.go +++ b/internal/cli/users_blocks.go @@ -1,7 +1,6 @@ package cli import ( - "errors" "fmt" "net/http" @@ -82,34 +81,30 @@ func deleteUserBlocksCmd(cli *cli) *cobra.Command { auth0 users blocks unblock "frederik@travel0.com" "poovam@travel0.com" `, RunE: func(cmd *cobra.Command, args []string) error { - identifiers := make([]string, len(args)) + ids := make([]string, len(args)) if len(args) == 0 { var id string if err := userIdentifier.Ask(cmd, &id); err != nil { return err } - identifiers = append(identifiers, id) + ids = append(ids, id) } else { - identifiers = append(identifiers, args...) + ids = append(ids, args...) } - return ansi.Spinner("Unblocking user(s)...", func() error { - var errs []error - for _, identifier := range identifiers { - if identifier != "" { - err := cli.api.User.Unblock(cmd.Context(), identifier) - if mErr, ok := err.(management.Error); ok && mErr.Status() != http.StatusBadRequest { - errs = append(errs, fmt.Errorf("failed to unblock user with identifier %q: %w", identifier, err)) - continue - } - - err = cli.api.User.UnblockByIdentifier(cmd.Context(), identifier) - if err != nil { - errs = append(errs, fmt.Errorf("failed to unblock user with identifier %q: %w", identifier, err)) - } + return ansi.ProgressBar("Unblocking user(s)", ids, func(_ int, id string) error { + if id != "" { + err := cli.api.User.Unblock(cmd.Context(), id) + if mErr, ok := err.(management.Error); ok && mErr.Status() != http.StatusBadRequest { + return fmt.Errorf("failed to unblock user with identifier %s: %w", id, err) + } + + err = cli.api.User.UnblockByIdentifier(cmd.Context(), id) + if err != nil { + return fmt.Errorf("failed to unblock user with identifier %s: %w", id, err) } } - return errors.Join(errs...) + return nil }) }, } diff --git a/internal/cli/utils_shared.go b/internal/cli/utils_shared.go index 61367b58a..95d1fd07d 100644 --- a/internal/cli/utils_shared.go +++ b/internal/cli/utils_shared.go @@ -186,7 +186,7 @@ func runLoginFlow(ctx context.Context, cli *cli, c *management.Client, connName, defer func() { if callbackAdded { if err := removeLocalCallbackURLFromClient(ctx, cli.api.Client, c); err != nil { // TODO: Make it a warning. - cli.renderer.Errorf("Unable to remove callback URL '%s' from client: %s", cliLoginTestingCallbackURL, err) + cli.renderer.Errorf("failed to remove callback URL '%s' from client: %s", cliLoginTestingCallbackURL, err) } } }() @@ -275,7 +275,7 @@ func containsStr(s []string, u string) bool { func openManageURL(cli *cli, tenant string, path string) { manageTenantURL := formatManageTenantURL(tenant, &cli.Config) if len(manageTenantURL) == 0 || len(path) == 0 { - cli.renderer.Warnf("Unable to format the correct URL, please ensure you have run 'auth0 login' and try again.") + cli.renderer.Warnf("Failed to format the correct URL, please ensure you have run 'auth0 login' and try again.") return }