From df204451bfa41d4ba2347277922384d4407bd80f Mon Sep 17 00:00:00 2001 From: Ma77C0nd0n Date: Thu, 15 Jun 2023 11:02:23 +0100 Subject: [PATCH 1/5] CLOUDP-184341: add flag for compacting list results --- internal/cli/atlas/alerts/settings/list.go | 8 +++- internal/cli/atlas/dbusers/list.go | 8 +++- .../cli/atlas/organizations/apikeys/list.go | 8 +++- internal/cli/atlas/processes/list.go | 8 +++- internal/cli/atlas/projects/apikeys/list.go | 8 +++- internal/cli/atlas/projects/users/list.go | 8 +++- internal/cli/atlas/teams/list.go | 8 +++- internal/cli/atlas/teams/users/list.go | 10 ++++- internal/cli/output_opts.go | 45 +++++++++++++++++++ internal/cli/output_opts_test.go | 34 ++++++++++++++ internal/flag/flags.go | 2 + internal/usage/usage.go | 1 + test/e2e/atlas/alert_settings_test.go | 22 +++++++++ test/e2e/atlas/dbusers_test.go | 18 ++++++++ test/e2e/atlas/processes_test.go | 21 +++++++++ test/e2e/iam/atlas_org_api_keys_test.go | 20 +++++++++ test/e2e/iam/atlas_project_api_keys_test.go | 20 +++++++++ test/e2e/iam/atlas_team_users_test.go | 19 ++++++++ test/e2e/iam/atlas_teams_test.go | 18 ++++++++ 19 files changed, 277 insertions(+), 9 deletions(-) diff --git a/internal/cli/atlas/alerts/settings/list.go b/internal/cli/atlas/alerts/settings/list.go index d058a2e440..0cc5d52fad 100644 --- a/internal/cli/atlas/alerts/settings/list.go +++ b/internal/cli/atlas/alerts/settings/list.go @@ -32,7 +32,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.AlertConfigurationLister + CompactResponse bool + store store.AlertConfigurationLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -58,6 +59,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -90,6 +95,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/dbusers/list.go b/internal/cli/atlas/dbusers/list.go index 263e020806..0c3303a989 100644 --- a/internal/cli/atlas/dbusers/list.go +++ b/internal/cli/atlas/dbusers/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.DatabaseUserLister + CompactResponse bool + store store.DatabaseUserLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -53,6 +54,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -84,6 +89,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/organizations/apikeys/list.go b/internal/cli/atlas/organizations/apikeys/list.go index 7b08fc2663..97b6228ea5 100644 --- a/internal/cli/atlas/organizations/apikeys/list.go +++ b/internal/cli/atlas/organizations/apikeys/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.OrganizationAPIKeyLister + CompactResponse bool + store store.OrganizationAPIKeyLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -53,6 +54,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -84,6 +89,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/processes/list.go b/internal/cli/atlas/processes/list.go index 30bfc00eec..f6580eff4c 100644 --- a/internal/cli/atlas/processes/list.go +++ b/internal/cli/atlas/processes/list.go @@ -37,7 +37,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.ProcessLister + CompactResponse bool + store store.ProcessLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -55,6 +56,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -100,6 +105,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/projects/apikeys/list.go b/internal/cli/atlas/projects/apikeys/list.go index aab218c693..e784baf619 100644 --- a/internal/cli/atlas/projects/apikeys/list.go +++ b/internal/cli/atlas/projects/apikeys/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.ProjectAPIKeyLister + CompactResponse bool + store store.ProjectAPIKeyLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -54,6 +55,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -85,6 +90,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/projects/users/list.go b/internal/cli/atlas/projects/users/list.go index 2dcdaf76a5..639d170843 100644 --- a/internal/cli/atlas/projects/users/list.go +++ b/internal/cli/atlas/projects/users/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.ProjectUsersLister + CompactResponse bool + store store.ProjectUsersLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -54,6 +55,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -85,6 +90,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/teams/list.go b/internal/cli/atlas/teams/list.go index 966af93de5..ce0132001a 100644 --- a/internal/cli/atlas/teams/list.go +++ b/internal/cli/atlas/teams/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.TeamLister + CompactResponse bool + store store.TeamLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -54,6 +55,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -85,6 +90,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/teams/users/list.go b/internal/cli/atlas/teams/users/list.go index aade5eda34..0391c936f7 100644 --- a/internal/cli/atlas/teams/users/list.go +++ b/internal/cli/atlas/teams/users/list.go @@ -34,8 +34,9 @@ const listTemplate = `ID FIRST NAME LAST NAME USERNAME EMAIL{{range .Results}} type ListOpts struct { cli.GlobalOpts cli.OutputOpts - store store.TeamUserLister - teamID string + CompactResponse bool + store store.TeamUserLister + teamID string } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -52,6 +53,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -82,6 +87,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) _ = cmd.MarkFlagRequired(flag.TeamID) diff --git a/internal/cli/output_opts.go b/internal/cli/output_opts.go index c344cfe12c..03ccabf1c0 100644 --- a/internal/cli/output_opts.go +++ b/internal/cli/output_opts.go @@ -15,12 +15,15 @@ package cli import ( + "encoding/json" "errors" "fmt" "io" "os" "strings" + "github.com/PaesslerAG/jsonpath" + "github.com/mongodb/mongodb-atlas-cli/internal/config" "github.com/mongodb/mongodb-atlas-cli/internal/jsonpathwriter" "github.com/mongodb/mongodb-atlas-cli/internal/jsonwriter" @@ -113,6 +116,48 @@ func (opts *OutputOpts) Print(o interface{}) error { return err } +func (opts *OutputOpts) PrintForCompactResultsResponse(o interface{}) error { + if opts.ConfigOutput() == jsonFormat { + o, err := mapReduceResults(o) + if err == nil { + return jsonwriter.Print(opts.ConfigWriter(), o) + } + } + + outputType, val := opts.outputTypeAndValue() + if outputType == jsonPath { + o, err := mapReduceResults(o) + if err == nil { + return jsonpathwriter.Print(opts.ConfigWriter(), val, o) + } + } + + t, err := template(outputType, val) + if err != nil { + return err + } + + if t != "" { + return templatewriter.Print(opts.ConfigWriter(), t, o) + } + _, err = fmt.Fprintln(opts.ConfigWriter(), o) + return err +} + +func mapReduceResults(o interface{}) (interface{}, error) { + jsonString, err := json.Marshal(o) + if err != nil { + return nil, err + } + + var val interface{} + if e := json.Unmarshal(jsonString, &val); e != nil { + return nil, e + } + + return jsonpath.Get("results", val) +} + // outputTypeAndValue returns the output type and the associated value // Current available output types are: // "go-template=Template string", diff --git a/internal/cli/output_opts_test.go b/internal/cli/output_opts_test.go index e3068fbd99..ffb1352460 100644 --- a/internal/cli/output_opts_test.go +++ b/internal/cli/output_opts_test.go @@ -18,7 +18,11 @@ package cli import ( "io" + "reflect" "testing" + + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" + "go.mongodb.org/atlas-sdk/admin" ) func TestOutputOpts_outputTypeAndValue(t *testing.T) { @@ -64,3 +68,33 @@ func TestOutputOpts_outputTypeAndValue(t *testing.T) { }) } } + +func TestOutputOpts_mapReduceResults(t *testing.T) { + t.Run("when results present", func(t *testing.T) { + input := *admin.NewPaginatedTeam() + wantID := "123" + wantName := "Team A" + input.Results = []admin.TeamResponse{ + { + Id: pointer.Get(wantID), + Name: pointer.Get(wantName), + }, + } + + compactResults, err := mapReduceResults(input) + if err != nil { + t.Fatalf("mapReduceResults() unexpected error: %v", err) + } + + mapArrayResponse := reflect.ValueOf(compactResults).Interface().([]interface{}) + mapResponse, _ := mapArrayResponse[0].(map[string]interface{}) + gotID, _ := mapResponse["id"] + gotName, _ := mapResponse["name"] + if gotID != wantID { + t.Errorf("mapReduceResults() got = %v, want %v", gotID, wantID) + } + if gotName != wantName { + t.Errorf("mapReduceResults() got = %v, want %v", gotName, wantName) + } + }) +} diff --git a/internal/flag/flags.go b/internal/flag/flags.go index 510e81e30a..88021a5a79 100644 --- a/internal/flag/flags.go +++ b/internal/flag/flags.go @@ -350,4 +350,6 @@ const ( EnableWatch = "watch" // EnableWatch flag EnableWatchShort = "w" // EnableWatchShort flag WatchTimeout = "watchTimeout" // WatchTimeout flag + CompactResponse = "compact" // CompactResponse flag to return compacted list response + CompactResponseShort = "c" // CompactResponseShort flag ) diff --git a/internal/usage/usage.go b/internal/usage/usage.go index e4c47ff5bb..d7ae05b5d8 100644 --- a/internal/usage/usage.go +++ b/internal/usage/usage.go @@ -433,4 +433,5 @@ dbName and collection are required only for built-in roles.` UpdateWarning = " Passing this flag replaces preexisting data." EnableWatch = "Watch the command until it completes its execution or the watch times out. To set the time that the watch times out, use the --watchTimeout option." WatchTimeout = "Time in seconds until a watch times out. After a watch times out, the CLI no longer watches the command." + CompactResponse = "Flag that enables the compact array response structure for json output on applicable list commands." ) diff --git a/test/e2e/atlas/alert_settings_test.go b/test/e2e/atlas/alert_settings_test.go index dbab1ebf53..761eb09e77 100644 --- a/test/e2e/atlas/alert_settings_test.go +++ b/test/e2e/atlas/alert_settings_test.go @@ -81,6 +81,28 @@ func TestAlertConfig(t *testing.T) { cmd.Env = os.Environ() resp, err := cmd.CombinedOutput() assert.NoError(t, err, string(resp)) + a := assert.New(t) + var config admin.PaginatedAlertConfig + if err := json.Unmarshal(resp, &config); a.NoError(err) { + a.NotEmpty(config.Results) + } + }) + + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + alertsEntity, + configEntity, + "-c", + "ls", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + assert.NoError(t, err, string(resp)) + a := assert.New(t) + var config []admin.AlertConfigViewForNdsGroup + if err := json.Unmarshal(resp, &config); a.NoError(err) { + a.NotEmpty(config) + } }) t.Run("Update", func(t *testing.T) { diff --git a/test/e2e/atlas/dbusers_test.go b/test/e2e/atlas/dbusers_test.go index 24c79210b2..4d5519b276 100644 --- a/test/e2e/atlas/dbusers_test.go +++ b/test/e2e/atlas/dbusers_test.go @@ -82,6 +82,24 @@ func TestDBUserWithFlags(t *testing.T) { } }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + dbusersEntity, + "ls", + "-c", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + require.NoError(t, err, string(resp)) + + var users []atlasv2.DatabaseUser + require.NoError(t, json.Unmarshal(resp, &users), string(resp)) + + if len(users) == 0 { + t.Fatalf("expected len(users) > 0, got 0") + } + }) + t.Run("Describe", func(t *testing.T) { testDescribeUser(t, cliPath, username) }) diff --git a/test/e2e/atlas/processes_test.go b/test/e2e/atlas/processes_test.go index 79a2639249..6236d08b11 100644 --- a/test/e2e/atlas/processes_test.go +++ b/test/e2e/atlas/processes_test.go @@ -55,6 +55,27 @@ func TestProcesses(t *testing.T) { } }) + t.Run("list compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + processesEntity, + "list", + "-p", + "--projectId", g.projectID, + "-o=json") + + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + var hostViewsCompact []atlasv2.HostViewAtlas + + if err := json.Unmarshal(resp, &hostViewsCompact); assert.NoError(t, err) { + require.NotEmpty(t, hostViewsCompact) + } + }) + t.Run("describe", func(t *testing.T) { cmd := exec.Command(cliPath, processesEntity, diff --git a/test/e2e/iam/atlas_org_api_keys_test.go b/test/e2e/iam/atlas_org_api_keys_test.go index a0d6d64d02..982bbc07ac 100644 --- a/test/e2e/iam/atlas_org_api_keys_test.go +++ b/test/e2e/iam/atlas_org_api_keys_test.go @@ -81,6 +81,26 @@ func TestAtlasOrgAPIKeys(t *testing.T) { assert.NotEmpty(t, keys.Results) }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + orgEntity, + apiKeysEntity, + "ls", + "-c", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + var keys []atlasv2.ApiUser + if err := json.Unmarshal(resp, &keys); err != nil { + t.Fatalf("unexpected error: %v", err) + } + assert.NotEmpty(t, keys) + }) + t.Run("Update", func(t *testing.T) { newDesc := "e2e-test-atlas-org-updated" cmd := exec.Command(cliPath, diff --git a/test/e2e/iam/atlas_project_api_keys_test.go b/test/e2e/iam/atlas_project_api_keys_test.go index 787886f557..ad45120623 100644 --- a/test/e2e/iam/atlas_project_api_keys_test.go +++ b/test/e2e/iam/atlas_project_api_keys_test.go @@ -102,6 +102,26 @@ func TestAtlasProjectAPIKeys(t *testing.T) { assert.NotEmpty(t, keys.Results) }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + projectsEntity, + apiKeysEntity, + "ls", + "-c", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + var keys []atlasv2.ApiUser + if err := json.Unmarshal(resp, &keys); err != nil { + t.Fatalf("unexpected error: %v", err) + } + assert.NotEmpty(t, keys) + }) + t.Run("Delete", func(t *testing.T) { cmd := exec.Command(cliPath, projectsEntity, diff --git a/test/e2e/iam/atlas_team_users_test.go b/test/e2e/iam/atlas_team_users_test.go index 0142170560..d87cd48d59 100644 --- a/test/e2e/iam/atlas_team_users_test.go +++ b/test/e2e/iam/atlas_team_users_test.go @@ -95,6 +95,25 @@ func TestAtlasTeamUsers(t *testing.T) { } }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + teamsEntity, + usersEntity, + "ls", + "-c", + "--teamId", + teamID, + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + require.NoError(t, err, string(resp)) + a := assert.New(t) + var teams []atlasv2.AppUser + if err := json.Unmarshal(resp, &teams); a.NoError(err) { + a.NotEmpty(teams) + } + }) + t.Run("Delete", func(t *testing.T) { cmd := exec.Command(cliPath, teamsEntity, diff --git a/test/e2e/iam/atlas_teams_test.go b/test/e2e/iam/atlas_teams_test.go index afee4c83d8..1526a5700a 100644 --- a/test/e2e/iam/atlas_teams_test.go +++ b/test/e2e/iam/atlas_teams_test.go @@ -123,6 +123,24 @@ func TestAtlasTeams(t *testing.T) { } }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + teamsEntity, + "-c", + "ls", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + a := assert.New(t) + a.NoError(err, string(resp)) + + var teams []atlasv2.TeamResponse + if err := json.Unmarshal(resp, &teams); a.NoError(err) { + a.NotEmpty(t, teams) + } + }) + t.Run("Delete", func(t *testing.T) { cmd := exec.Command(cliPath, teamsEntity, From 60de93b66c24d440bb56dbf2cecb086b399e6f38 Mon Sep 17 00:00:00 2001 From: Ma77C0nd0n Date: Thu, 15 Jun 2023 11:19:57 +0100 Subject: [PATCH 2/5] doc changes --- docs/atlascli/command/atlas-alerts-settings-list.txt | 4 ++++ docs/atlascli/command/atlas-dbusers-list.txt | 4 ++++ docs/atlascli/command/atlas-organizations-apiKeys-list.txt | 4 ++++ docs/atlascli/command/atlas-processes-list.txt | 4 ++++ docs/atlascli/command/atlas-projects-apiKeys-list.txt | 4 ++++ docs/atlascli/command/atlas-projects-users-list.txt | 4 ++++ docs/atlascli/command/atlas-teams-list.txt | 4 ++++ docs/atlascli/command/atlas-teams-users-list.txt | 4 ++++ docs/mongocli/command/mongocli-atlas-dbusers-list.txt | 4 ++++ docs/mongocli/command/mongocli-atlas-processes-list.txt | 4 ++++ 10 files changed, 40 insertions(+) diff --git a/docs/atlascli/command/atlas-alerts-settings-list.txt b/docs/atlascli/command/atlas-alerts-settings-list.txt index 07497a19e3..3068ec212c 100644 --- a/docs/atlascli/command/atlas-alerts-settings-list.txt +++ b/docs/atlascli/command/atlas-alerts-settings-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-dbusers-list.txt b/docs/atlascli/command/atlas-dbusers-list.txt index 0846862a80..fb87882555 100644 --- a/docs/atlascli/command/atlas-dbusers-list.txt +++ b/docs/atlascli/command/atlas-dbusers-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-organizations-apiKeys-list.txt b/docs/atlascli/command/atlas-organizations-apiKeys-list.txt index 4a49cb86e3..5d2e797581 100644 --- a/docs/atlascli/command/atlas-organizations-apiKeys-list.txt +++ b/docs/atlascli/command/atlas-organizations-apiKeys-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-processes-list.txt b/docs/atlascli/command/atlas-processes-list.txt index fd9c756670..5d79c25ffc 100644 --- a/docs/atlascli/command/atlas-processes-list.txt +++ b/docs/atlascli/command/atlas-processes-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-projects-apiKeys-list.txt b/docs/atlascli/command/atlas-projects-apiKeys-list.txt index 0a692e5956..01b31449d8 100644 --- a/docs/atlascli/command/atlas-projects-apiKeys-list.txt +++ b/docs/atlascli/command/atlas-projects-apiKeys-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-projects-users-list.txt b/docs/atlascli/command/atlas-projects-users-list.txt index 5f8eed4a9e..cb2798f5fe 100644 --- a/docs/atlascli/command/atlas-projects-users-list.txt +++ b/docs/atlascli/command/atlas-projects-users-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-teams-list.txt b/docs/atlascli/command/atlas-teams-list.txt index bcdfb03e79..3cc82899dc 100644 --- a/docs/atlascli/command/atlas-teams-list.txt +++ b/docs/atlascli/command/atlas-teams-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-teams-users-list.txt b/docs/atlascli/command/atlas-teams-users-list.txt index 321c689e59..b08eb44e05 100644 --- a/docs/atlascli/command/atlas-teams-users-list.txt +++ b/docs/atlascli/command/atlas-teams-users-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/mongocli/command/mongocli-atlas-dbusers-list.txt b/docs/mongocli/command/mongocli-atlas-dbusers-list.txt index 99419a3f12..f370ab43d8 100644 --- a/docs/mongocli/command/mongocli-atlas-dbusers-list.txt +++ b/docs/mongocli/command/mongocli-atlas-dbusers-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false diff --git a/docs/mongocli/command/mongocli-atlas-processes-list.txt b/docs/mongocli/command/mongocli-atlas-processes-list.txt index f0bc89e233..70ecec1f1d 100644 --- a/docs/mongocli/command/mongocli-atlas-processes-list.txt +++ b/docs/mongocli/command/mongocli-atlas-processes-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for json output on applicable list commands. * - -h, --help - - false From 786d38284bcaea5695520174fb1d9770d9ce492d Mon Sep 17 00:00:00 2001 From: Ma77C0nd0n Date: Thu, 15 Jun 2023 11:55:21 +0100 Subject: [PATCH 3/5] fix linting errors --- internal/cli/output_opts.go | 9 ++++----- internal/cli/output_opts_test.go | 6 +++--- test/e2e/atlas/alert_settings_test.go | 2 +- test/e2e/iam/atlas_teams_test.go | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/cli/output_opts.go b/internal/cli/output_opts.go index 03ccabf1c0..a372946877 100644 --- a/internal/cli/output_opts.go +++ b/internal/cli/output_opts.go @@ -23,7 +23,6 @@ import ( "strings" "github.com/PaesslerAG/jsonpath" - "github.com/mongodb/mongodb-atlas-cli/internal/config" "github.com/mongodb/mongodb-atlas-cli/internal/jsonpathwriter" "github.com/mongodb/mongodb-atlas-cli/internal/jsonwriter" @@ -118,17 +117,17 @@ func (opts *OutputOpts) Print(o interface{}) error { func (opts *OutputOpts) PrintForCompactResultsResponse(o interface{}) error { if opts.ConfigOutput() == jsonFormat { - o, err := mapReduceResults(o) + compactResponse, err := mapReduceResults(o) if err == nil { - return jsonwriter.Print(opts.ConfigWriter(), o) + return jsonwriter.Print(opts.ConfigWriter(), compactResponse) } } outputType, val := opts.outputTypeAndValue() if outputType == jsonPath { - o, err := mapReduceResults(o) + compactResponse, err := mapReduceResults(o) if err == nil { - return jsonpathwriter.Print(opts.ConfigWriter(), val, o) + return jsonpathwriter.Print(opts.ConfigWriter(), val, compactResponse) } } diff --git a/internal/cli/output_opts_test.go b/internal/cli/output_opts_test.go index ffb1352460..6830adf157 100644 --- a/internal/cli/output_opts_test.go +++ b/internal/cli/output_opts_test.go @@ -87,9 +87,9 @@ func TestOutputOpts_mapReduceResults(t *testing.T) { } mapArrayResponse := reflect.ValueOf(compactResults).Interface().([]interface{}) - mapResponse, _ := mapArrayResponse[0].(map[string]interface{}) - gotID, _ := mapResponse["id"] - gotName, _ := mapResponse["name"] + mapResponse := mapArrayResponse[0].(map[string]interface{}) + gotID := mapResponse["id"] + gotName := mapResponse["name"] if gotID != wantID { t.Errorf("mapReduceResults() got = %v, want %v", gotID, wantID) } diff --git a/test/e2e/atlas/alert_settings_test.go b/test/e2e/atlas/alert_settings_test.go index 761eb09e77..0cf7996cd1 100644 --- a/test/e2e/atlas/alert_settings_test.go +++ b/test/e2e/atlas/alert_settings_test.go @@ -92,8 +92,8 @@ func TestAlertConfig(t *testing.T) { cmd := exec.Command(cliPath, alertsEntity, configEntity, - "-c", "ls", + "-c", "-o=json") cmd.Env = os.Environ() resp, err := cmd.CombinedOutput() diff --git a/test/e2e/iam/atlas_teams_test.go b/test/e2e/iam/atlas_teams_test.go index 1526a5700a..635d876216 100644 --- a/test/e2e/iam/atlas_teams_test.go +++ b/test/e2e/iam/atlas_teams_test.go @@ -126,8 +126,8 @@ func TestAtlasTeams(t *testing.T) { t.Run("List Compact", func(t *testing.T) { cmd := exec.Command(cliPath, teamsEntity, - "-c", "ls", + "-c", "-o=json") cmd.Env = os.Environ() resp, err := cmd.CombinedOutput() From 180f91e5284a2350d1452995394f7d4cc8ac11cc Mon Sep 17 00:00:00 2001 From: Matt Condon Date: Thu, 15 Jun 2023 14:37:58 +0100 Subject: [PATCH 4/5] docs: more dea Co-authored-by: Sarah Simpers <82042374+sarahsimpers@users.noreply.github.com> --- internal/usage/usage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/usage/usage.go b/internal/usage/usage.go index d7ae05b5d8..829f0beaa9 100644 --- a/internal/usage/usage.go +++ b/internal/usage/usage.go @@ -433,5 +433,5 @@ dbName and collection are required only for built-in roles.` UpdateWarning = " Passing this flag replaces preexisting data." EnableWatch = "Watch the command until it completes its execution or the watch times out. To set the time that the watch times out, use the --watchTimeout option." WatchTimeout = "Time in seconds until a watch times out. After a watch times out, the CLI no longer watches the command." - CompactResponse = "Flag that enables the compact array response structure for json output on applicable list commands." + CompactResponse = "Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option." ) From 7f3eba4192a2119f2e89aad5fd2a21c959bd161b Mon Sep 17 00:00:00 2001 From: Ma77C0nd0n Date: Thu, 15 Jun 2023 14:43:57 +0100 Subject: [PATCH 5/5] make gen-docs --- docs/atlascli/command/atlas-alerts-settings-list.txt | 2 +- docs/atlascli/command/atlas-dbusers-list.txt | 2 +- docs/atlascli/command/atlas-organizations-apiKeys-list.txt | 2 +- docs/atlascli/command/atlas-processes-list.txt | 2 +- docs/atlascli/command/atlas-projects-apiKeys-list.txt | 2 +- docs/atlascli/command/atlas-projects-users-list.txt | 2 +- docs/atlascli/command/atlas-teams-list.txt | 2 +- docs/atlascli/command/atlas-teams-users-list.txt | 2 +- docs/mongocli/command/mongocli-atlas-dbusers-list.txt | 2 +- docs/mongocli/command/mongocli-atlas-processes-list.txt | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/atlascli/command/atlas-alerts-settings-list.txt b/docs/atlascli/command/atlas-alerts-settings-list.txt index 3068ec212c..3921094e7f 100644 --- a/docs/atlascli/command/atlas-alerts-settings-list.txt +++ b/docs/atlascli/command/atlas-alerts-settings-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-dbusers-list.txt b/docs/atlascli/command/atlas-dbusers-list.txt index fb87882555..ae95051c97 100644 --- a/docs/atlascli/command/atlas-dbusers-list.txt +++ b/docs/atlascli/command/atlas-dbusers-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-organizations-apiKeys-list.txt b/docs/atlascli/command/atlas-organizations-apiKeys-list.txt index 5d2e797581..51637479c1 100644 --- a/docs/atlascli/command/atlas-organizations-apiKeys-list.txt +++ b/docs/atlascli/command/atlas-organizations-apiKeys-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-processes-list.txt b/docs/atlascli/command/atlas-processes-list.txt index 5d79c25ffc..be3160085f 100644 --- a/docs/atlascli/command/atlas-processes-list.txt +++ b/docs/atlascli/command/atlas-processes-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-projects-apiKeys-list.txt b/docs/atlascli/command/atlas-projects-apiKeys-list.txt index 01b31449d8..36d079888c 100644 --- a/docs/atlascli/command/atlas-projects-apiKeys-list.txt +++ b/docs/atlascli/command/atlas-projects-apiKeys-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-projects-users-list.txt b/docs/atlascli/command/atlas-projects-users-list.txt index cb2798f5fe..32b34cc926 100644 --- a/docs/atlascli/command/atlas-projects-users-list.txt +++ b/docs/atlascli/command/atlas-projects-users-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-teams-list.txt b/docs/atlascli/command/atlas-teams-list.txt index 3cc82899dc..d5ad37b016 100644 --- a/docs/atlascli/command/atlas-teams-list.txt +++ b/docs/atlascli/command/atlas-teams-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-teams-users-list.txt b/docs/atlascli/command/atlas-teams-users-list.txt index b08eb44e05..994b1fd8e9 100644 --- a/docs/atlascli/command/atlas-teams-users-list.txt +++ b/docs/atlascli/command/atlas-teams-users-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/mongocli/command/mongocli-atlas-dbusers-list.txt b/docs/mongocli/command/mongocli-atlas-dbusers-list.txt index f370ab43d8..ecba954d20 100644 --- a/docs/mongocli/command/mongocli-atlas-dbusers-list.txt +++ b/docs/mongocli/command/mongocli-atlas-dbusers-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/mongocli/command/mongocli-atlas-processes-list.txt b/docs/mongocli/command/mongocli-atlas-processes-list.txt index 70ecec1f1d..0732f253cd 100644 --- a/docs/mongocli/command/mongocli-atlas-processes-list.txt +++ b/docs/mongocli/command/mongocli-atlas-processes-list.txt @@ -40,7 +40,7 @@ Options * - -c, --compact - - false - - Flag that enables the compact array response structure for json output on applicable list commands. + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false