From 211f739c2a6800de9a28a7dc217fb8fe7b685ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0af=C3=A1=C5=99?= Date: Thu, 21 Jul 2022 13:55:43 +0200 Subject: [PATCH] feat(service-registry): added --all-groups flag in artifact list command (#1667) --- docs/commands/rhoas_service-registry_artifact_list.md | 4 ++++ pkg/cmd/registry/artifact/crud/list/list.go | 11 ++++++++--- pkg/core/localize/locales/en/cmd/artifact.en.toml | 6 ++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/commands/rhoas_service-registry_artifact_list.md b/docs/commands/rhoas_service-registry_artifact_list.md index ec43cbb9c..2e27aa85c 100644 --- a/docs/commands/rhoas_service-registry_artifact_list.md +++ b/docs/commands/rhoas_service-registry_artifact_list.md @@ -16,6 +16,9 @@ rhoas service-registry artifact list [flags] ## List all artifacts for the "default" artifact group rhoas service-registry artifact list +## List all artifacts in all groups +rhoas service-registry artifact list --all-groups + ## List all artifacts with "my-group" group rhoas service-registry artifact list --group=my-group @@ -36,6 +39,7 @@ rhoas service-registry artifact list --description sample ### Options ``` + -a, --all-groups List artifacts in all groups --description string Text search to filter artifacts by description -g, --group string Artifact group (default "default") --instance-id string ID of the Service Registry instance to be used (by default, uses the currently selected instance) diff --git a/pkg/cmd/registry/artifact/crud/list/list.go b/pkg/cmd/registry/artifact/crud/list/list.go index 7acb5053a..596d7e0f4 100644 --- a/pkg/cmd/registry/artifact/crud/list/list.go +++ b/pkg/cmd/registry/artifact/crud/list/list.go @@ -35,7 +35,8 @@ type artifactRow struct { } type options struct { - group string + group string + allGroups bool registryID string outputFormat string @@ -95,6 +96,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command { } cmd.Flags().StringVarP(&opts.group, "group", "g", registrycmdutil.DefaultArtifactGroup, opts.localizer.MustLocalize("artifact.common.group")) + cmd.Flags().BoolVarP(&opts.allGroups, "all-groups", "a", false, opts.localizer.MustLocalize("artifact.cmd.list.flag.allgroups.description")) cmd.Flags().Int32VarP(&opts.page, "page", "", 1, opts.localizer.MustLocalize("artifact.common.page.number")) cmd.Flags().Int32VarP(&opts.limit, "limit", "", 100, opts.localizer.MustLocalize("artifact.common.page.limit")) @@ -112,7 +114,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command { } func runList(opts *options) error { - if opts.group == registrycmdutil.DefaultArtifactGroup { + if opts.group == registrycmdutil.DefaultArtifactGroup && !opts.allGroups { opts.Logger.Info(opts.localizer.MustLocalize("registry.artifact.common.message.no.group", localize.NewEntry("DefaultArtifactGroup", registrycmdutil.DefaultArtifactGroup))) } @@ -129,12 +131,15 @@ func runList(opts *options) error { } request := a.SearchApi.SearchArtifacts(opts.Context) - request = request.Group(opts.group) request = request.Offset((opts.page - 1) * opts.limit) request = request.Limit(opts.limit) request = request.Orderby(registryinstanceclient.SORTBY_CREATED_ON) request = request.Order(registryinstanceclient.SORTORDER_ASC) + if !opts.allGroups { + request = request.Group(opts.group) + } + if opts.name != "" { request = request.Name(opts.name) } diff --git a/pkg/core/localize/locales/en/cmd/artifact.en.toml b/pkg/core/localize/locales/en/cmd/artifact.en.toml index 1dcc925fa..b4d50a886 100644 --- a/pkg/core/localize/locales/en/cmd/artifact.en.toml +++ b/pkg/core/localize/locales/en/cmd/artifact.en.toml @@ -293,6 +293,9 @@ one = ''' ## List all artifacts for the "default" artifact group rhoas service-registry artifact list +## List all artifacts in all groups +rhoas service-registry artifact list --all-groups + ## List all artifacts with "my-group" group rhoas service-registry artifact list --group=my-group @@ -486,6 +489,9 @@ one = 'Successfully updated artifact state' [artifact.cmd.state.error.invalidArtifactState] one = 'invalid artifact state. Please use one of following values: {{.AllowedTypes}}' +[artifact.cmd.list.flag.allgroups.description] +one= 'List artifacts in all groups' + [artifact.cmd.list.flag.name.description] one = 'Text search to filter artifacts by name'