From 4232ef7e5dfda32f4f7b10632f4c4ccbf68ce9d2 Mon Sep 17 00:00:00 2001 From: Lohit Kolluri Date: Tue, 26 May 2026 17:03:37 +0530 Subject: [PATCH] fix(registry): use RepositoryV2 displayer for list-v2 commands The list-v2 subcommands registered the v1 Repository displayer, which advertised the wrong --format columns and broke scripted output that relies on --format and --no-header. Fixes digitalocean/doctl#1797 --- commands/displayers/registry.go | 2 +- commands/registry.go | 4 ++-- commands/registry_test.go | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/commands/displayers/registry.go b/commands/displayers/registry.go index ddca69f7b..1c7c01949 100644 --- a/commands/displayers/registry.go +++ b/commands/displayers/registry.go @@ -113,7 +113,7 @@ type RepositoryV2 struct { Repositories []do.RepositoryV2 } -var _ Displayable = &Repository{} +var _ Displayable = &RepositoryV2{} func (r *RepositoryV2) JSON(out io.Writer) error { return writeJSON(r.Repositories, out) diff --git a/commands/registry.go b/commands/registry.go index 48a34a966..481a7c30d 100644 --- a/commands/registry.go +++ b/commands/registry.go @@ -181,7 +181,7 @@ func Repository() *Command { cmd, RunListRepositoriesV2, "list-v2", "List repositories for a container registry", listRepositoriesV2Desc, - Writer, aliasOpt("ls2"), displayerType(&displayers.Repository{}), + Writer, aliasOpt("ls2"), displayerType(&displayers.RepositoryV2{}), ) cmdListRepositoriesV2.overrideNS = overrideNS addRegistryFlag(cmdListRepositoriesV2) @@ -1581,7 +1581,7 @@ func RegistriesRepository() *Command { cmd, RunRegistriesListRepositoriesV2, "list-v2 ", "List repositories for a container registry", listRepositoriesV2Desc, - Writer, aliasOpt("ls2"), displayerType(&displayers.Repository{}), + Writer, aliasOpt("ls2"), displayerType(&displayers.RepositoryV2{}), ) cmdListRepositoriesV2.overrideNS = overrideNS cmdListRepositoriesV2.Example = `The following example lists repositories in a registry named ` + "`" + `example-registry` + "`" + ` and uses the ` + "`" + `--format` + "`" + ` flag to return only the name and update time of each repository: doctl registries repository list-v2 example-registry --format Name,UpdatedAt` diff --git a/commands/registry_test.go b/commands/registry_test.go index 95d56431d..e83f18f6e 100644 --- a/commands/registry_test.go +++ b/commands/registry_test.go @@ -334,6 +334,24 @@ func TestRepositoryListV2(t *testing.T) { assert.False(t, strings.Contains(output, testRepositoryV2NoTags.LatestManifest.Blobs[0].Digest)) }) }) + + t.Run("respects format and no-header flags", func(t *testing.T) { + withTestClient(t, func(config *CmdConfig, tm *tcMocks) { + tm.registry.EXPECT().Get().Return(&testRegistry, nil) + tm.registry.EXPECT().ListRepositoriesV2(testRepositoryV2.RegistryName).Return([]do.RepositoryV2{testRepositoryV2}, nil) + + config.NS = "registry.repository.list-v2" + config.Doit.Set(config.NS, doctl.ArgFormat, "Name") + config.Doit.Set(config.NS, doctl.ArgNoHeader, true) + + var buf bytes.Buffer + config.Out = &buf + err := RunListRepositoriesV2(config) + assert.NoError(t, err) + + assert.Equal(t, testRepositoryV2.Name+"\n", buf.String()) + }) + }) } func TestRepositoryListTags(t *testing.T) {