Skip to content

Commit 59ff4a8

Browse files
segf00ltharshmaru7
andauthored
distinguish subcommands with overrideNS (#1752)
Co-authored-by: Harsh Maru <38807407+harshmaru7@users.noreply.github.com>
1 parent dfcae6f commit 59ff4a8

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

commands/registry.go

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ func Registry() *Command {
6666
},
6767
}
6868

69-
cmd.AddCommand(Repository())
70-
cmd.AddCommand(GarbageCollection())
71-
cmd.AddCommand(RegistryOptions())
72-
7369
createRegDesc := "Creates a new private container registry with the provided name."
7470
cmdRunRegistryCreate := CmdBuilder(cmd, RunRegistryCreate, "create <registry-name>",
7571
"Create a private container registry", createRegDesc, Writer)
@@ -136,6 +132,10 @@ By default this command generates read-only credentials. Use the ` + "`" + `--re
136132
"The length of time the registry credentials are valid for, in seconds. By default, the credentials do not expire.")
137133
cmdRunDockerConfig.Example = `The following example generates a Docker configuration for a registry named ` + "`" + `example-registry` + "`" + ` and uses the ` + "`" + `--expiry-seconds` + "`" + ` to set the credentials to expire after one day: doctl registry docker-config example-registry --expiry-seconds=86400`
138134

135+
cmd.AddCommand(Repository())
136+
cmd.AddCommand(GarbageCollection())
137+
cmd.AddCommand(RegistryOptions())
138+
139139
return cmd
140140
}
141141

@@ -150,6 +150,8 @@ func Repository() *Command {
150150
},
151151
}
152152

153+
overrideNS := "registry.repository"
154+
153155
listRepositoriesDesc := `Retrieves information about repositories in a registry, including:
154156
- The repository name
155157
- The latest tag for the repository
@@ -164,6 +166,7 @@ func Repository() *Command {
164166
Writer, aliasOpt("ls"), displayerType(&displayers.Repository{}),
165167
hiddenCmd(),
166168
)
169+
cmdListRepositories.overrideNS = overrideNS
167170
addRegistryFlag(cmdListRepositories)
168171
cmdListRepositories.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 registry repository list --format Name,UpdatedAt`
169172

@@ -180,6 +183,7 @@ func Repository() *Command {
180183
"List repositories for a container registry", listRepositoriesV2Desc,
181184
Writer, aliasOpt("ls2"), displayerType(&displayers.Repository{}),
182185
)
186+
cmdListRepositoriesV2.overrideNS = overrideNS
183187
addRegistryFlag(cmdListRepositoriesV2)
184188
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 registry repository list-v2 --format Name,UpdatedAt`
185189

@@ -195,6 +199,7 @@ func Repository() *Command {
195199
"List tags for a repository in a container registry", listRepositoryTagsDesc,
196200
Writer, aliasOpt("lt"), displayerType(&displayers.RepositoryTag{}),
197201
)
202+
cmdListRepositoryTags.overrideNS = overrideNS
198203
addRegistryFlag(cmdListRepositoryTags)
199204
cmdListRepositoryTags.Example = `The following example lists tags in a repository named ` + "`" + `example-repository` + "`" + ` in a registry named ` + "`" + `example-registry` + "`" + `. The command also uses the ` + "`" + `--format` + "`" + ` flag to return only the tag name and manifest digest for each tag: doctl registry repository list-tags example-repository --format Tag,ManifestDigest`
200205

@@ -208,6 +213,7 @@ func Repository() *Command {
208213
Writer,
209214
aliasOpt("dt"),
210215
)
216+
cmdRunRepositoryDeleteTag.overrideNS = overrideNS
211217
addRegistryFlag(cmdRunRepositoryDeleteTag)
212218
AddBoolFlag(cmdRunRepositoryDeleteTag, doctl.ArgForce, doctl.ArgShortForce, false, "Delete tag without confirmation prompt")
213219
cmdRunRepositoryDeleteTag.Example = `The following example deletes a tag named ` + "`" + `web` + "`" + ` from a repository named ` + "`" + `example-repository` + "`" + ` in a registry named ` + "`" + `example-registry` + "`" + `: doctl registry repository delete-tag example-repository web`
@@ -226,6 +232,7 @@ func Repository() *Command {
226232
"List manifests for a repository in a container registry", listRepositoryManifests,
227233
Writer, aliasOpt("lm"), displayerType(&displayers.RepositoryManifest{}),
228234
)
235+
cmdListRepositoryManifests.overrideNS = overrideNS
229236
addRegistryFlag(cmdListRepositoryManifests)
230237
cmdListRepositoryManifests.Example = `The following example lists manifests in a repository named ` + "`" + `example-repository` + "`" + `. The command also uses the ` + "`" + `--format` + "`" + ` flag to return only the digest and update time for each manifest: doctl registry repository list-manifests example-repository --format Digest,UpdatedAt`
231238

@@ -239,6 +246,7 @@ func Repository() *Command {
239246
Writer,
240247
aliasOpt("dm"),
241248
)
249+
cmdRunRepositoryDeleteManifest.overrideNS = overrideNS
242250
addRegistryFlag(cmdRunRepositoryDeleteManifest)
243251
AddBoolFlag(cmdRunRepositoryDeleteManifest, doctl.ArgForce, doctl.ArgShortForce, false, "Deletes manifest without confirmation prompt")
244252
cmdRunRepositoryDeleteManifest.Example = `The following example deletes a manifest with digest ` + "`" + `sha256:1234567890abcdef` + "`" + ` from a repository named ` + "`" + `example-repository` + "`" + ` in a registry named ` + "`" + `example-registry` + "`" + `: doctl registry repository delete-manifest example-repository sha256:a67c20e45178d90cbe686575719bd81f279b06842dc77521690e292c1eea685`
@@ -262,6 +270,8 @@ func GarbageCollection() *Command {
262270
},
263271
}
264272

273+
overrideNS := "registry.garbage-collection"
274+
265275
runStartGarbageCollectionDesc := "Starts a garbage collection on a container registry. You can only have one active garbage collection at a time for a given registry."
266276
cmdStartGarbageCollection := CmdBuilder(
267277
cmd,
@@ -273,6 +283,7 @@ func GarbageCollection() *Command {
273283
aliasOpt("s"),
274284
displayerType(&displayers.GarbageCollection{}),
275285
)
286+
cmdStartGarbageCollection.overrideNS = overrideNS
276287
AddBoolFlag(cmdStartGarbageCollection, doctl.ArgGCIncludeUntaggedManifests, "", false,
277288
"Include untagged manifests in garbage collection.")
278289
AddBoolFlag(cmdStartGarbageCollection, doctl.ArgGCExcludeUnreferencedBlobs, "", false,
@@ -301,6 +312,7 @@ func GarbageCollection() *Command {
301312
aliasOpt("ga", "g"),
302313
displayerType(&displayers.GarbageCollection{}),
303314
)
315+
cmdGetGarbageCollection.overrideNS = overrideNS
304316
cmdGetGarbageCollection.Example = `The following example retrieves the currently-active garbage collection for a registry: doctl registry garbage-collection get-active
305317
306318
The following example retrieves the currently-active garbage collection for a registry named ` + "`" + `example-registry` + "`" + `: doctl registry garbage-collection get-active example-registry`
@@ -316,6 +328,7 @@ The following example retrieves the currently-active garbage collection for a re
316328
aliasOpt("ls", "l"),
317329
displayerType(&displayers.GarbageCollection{}),
318330
)
331+
cmdListGarbageCollections.overrideNS = overrideNS
319332
cmdListGarbageCollections.Example = `The following example retrieves a list of past garbage collections for a registry: doctl registry garbage-collection list
320333
321334
The following example retrieves a list of past garbage collections for a registry named ` + "`" + `example-registry` + "`" + `: doctl registry garbage-collection list example-registry`
@@ -330,6 +343,7 @@ The following example retrieves a list of past garbage collections for a registr
330343
Writer,
331344
aliasOpt("c"),
332345
)
346+
cmdCancelGarbageCollection.overrideNS = overrideNS
333347
cmdCancelGarbageCollection.Example = `The following example cancels the garbage collection with the uuid` + "`" + `gc-uuid` + "`" + `for a registry: doctl registry garbage-collection cancel gc-uuid
334348
335349
The following example cancels the garbage collection with the uuid ` + "`" + `gc-uuid` + "`" + ` for a registry named ` + "`" + `example-registry` + "`" + `: doctl registry garbage-collection cancel example-registry gc-uuid`
@@ -348,10 +362,14 @@ func RegistryOptions() *Command {
348362
},
349363
}
350364

365+
overrideNS := "registry.options"
366+
351367
tiersDesc := "Lists available container registry subscription tiers"
352-
CmdBuilder(cmd, RunRegistryOptionsTiers, "subscription-tiers", tiersDesc, tiersDesc, Writer, aliasOpt("tiers"))
368+
cmdRegistryOptionTiers := CmdBuilder(cmd, RunRegistryOptionsTiers, "subscription-tiers", tiersDesc, tiersDesc, Writer, aliasOpt("tiers"))
369+
cmdRegistryOptionTiers.overrideNS = overrideNS
353370
regionsDesc := "Lists available container registry regions"
354-
CmdBuilder(cmd, RunGetRegistryOptionsRegions, "available-regions", regionsDesc, regionsDesc, Writer, aliasOpt("regions"))
371+
cmdGetRegistryOptionsRegions := CmdBuilder(cmd, RunGetRegistryOptionsRegions, "available-regions", regionsDesc, regionsDesc, Writer, aliasOpt("regions"))
372+
cmdGetRegistryOptionsRegions.overrideNS = overrideNS
355373

356374
return cmd
357375
}
@@ -1496,6 +1514,8 @@ func RegistriesRepository() *Command {
14961514
},
14971515
}
14981516

1517+
overrideNS := "registries.repository"
1518+
14991519
listRepositoriesDesc := `Retrieves information about repositories in a registry, including:
15001520
- The repository name
15011521
- The latest tag for the repository
@@ -1510,6 +1530,7 @@ func RegistriesRepository() *Command {
15101530
Writer, aliasOpt("ls"), displayerType(&displayers.Repository{}),
15111531
hiddenCmd(),
15121532
)
1533+
cmdListRepositories.overrideNS = overrideNS
15131534
cmdListRepositories.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 example-registry --format Name,UpdatedAt`
15141535

15151536
listRepositoriesV2Desc := `Retrieves information about repositories in a registry, including:
@@ -1525,6 +1546,7 @@ func RegistriesRepository() *Command {
15251546
"List repositories for a container registry", listRepositoriesV2Desc,
15261547
Writer, aliasOpt("ls2"), displayerType(&displayers.Repository{}),
15271548
)
1549+
cmdListRepositoriesV2.overrideNS = overrideNS
15281550
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`
15291551

15301552
listRepositoryTagsDesc := `Retrieves information about tags in a repository, including:
@@ -1539,6 +1561,7 @@ func RegistriesRepository() *Command {
15391561
"List tags for a repository in a container registry", listRepositoryTagsDesc,
15401562
Writer, aliasOpt("lt"), displayerType(&displayers.RepositoryTag{}),
15411563
)
1564+
cmdListRepositoryTags.overrideNS = overrideNS
15421565
cmdListRepositoryTags.Example = `The following example lists tags in a repository named ` + "`" + `example-repository` + "`" + ` in a registry named ` + "`" + `example-registry` + "`" + `. The command also uses the ` + "`" + `--format` + "`" + ` flag to return only the tag name and manifest digest for each tag: doctl registries repository list-tags example-registry example-repository --format Tag,ManifestDigest`
15431566

15441567
deleteTagDesc := "Permanently deletes one or more repository tags."
@@ -1551,6 +1574,7 @@ func RegistriesRepository() *Command {
15511574
Writer,
15521575
aliasOpt("dt"),
15531576
)
1577+
cmdRunRepositoryDeleteTag.overrideNS = overrideNS
15541578
AddBoolFlag(cmdRunRepositoryDeleteTag, doctl.ArgForce, doctl.ArgShortForce, false, "Delete tag without confirmation prompt")
15551579
cmdRunRepositoryDeleteTag.Example = `The following example deletes a tag named ` + "`" + `web` + "`" + ` from a repository named ` + "`" + `example-repository` + "`" + ` in a registry named ` + "`" + `example-registry` + "`" + `: doctl registries repository delete-tag example-registry example-repository web`
15561580

@@ -1568,6 +1592,7 @@ func RegistriesRepository() *Command {
15681592
"List manifests for a repository in a container registry", listRepositoryManifests,
15691593
Writer, aliasOpt("lm"), displayerType(&displayers.RepositoryManifest{}),
15701594
)
1595+
cmdListRepositoryManifests.overrideNS = overrideNS
15711596
cmdListRepositoryManifests.Example = `The following example lists manifests in a repository named ` + "`" + `example-repository` + "`" + ` in a registry named ` + "`" + `example-registry` + "`" + `. The command also uses the ` + "`" + `--format` + "`" + ` flag to return only the digest and update time for each manifest: doctl registries repository list-manifests example-registry example-repository --format Digest,UpdatedAt`
15721597

15731598
deleteManifestDesc := "Permanently deletes one or more repository manifests by digest."
@@ -1580,6 +1605,7 @@ func RegistriesRepository() *Command {
15801605
Writer,
15811606
aliasOpt("dm"),
15821607
)
1608+
cmdRunRepositoryDeleteManifest.overrideNS = overrideNS
15831609
AddBoolFlag(cmdRunRepositoryDeleteManifest, doctl.ArgForce, doctl.ArgShortForce, false, "Deletes manifest without confirmation prompt")
15841610
cmdRunRepositoryDeleteManifest.Example = `The following example deletes a manifest with digest ` + "`" + `sha256:1234567890abcdef` + "`" + ` from a repository named ` + "`" + `example-repository` + "`" + ` in a registry named ` + "`" + `example-registry` + "`" + `: doctl registries repository delete-manifest example-registry example-repository sha256:a67c20e45178d90cbe686575719bd81f279b06842dc77521690e292c1eea685`
15851611

@@ -1597,6 +1623,8 @@ func RegistriesGarbageCollection() *Command {
15971623
},
15981624
}
15991625

1626+
overrideNS := "registries.garbage-collection"
1627+
16001628
runStartGarbageCollectionDesc := "Starts a garbage collection on a container registry. You can only have one active garbage collection at a time for a given registry."
16011629
cmdStartGarbageCollection := CmdBuilder(
16021630
cmd,
@@ -1608,6 +1636,7 @@ func RegistriesGarbageCollection() *Command {
16081636
aliasOpt("s"),
16091637
displayerType(&displayers.GarbageCollection{}),
16101638
)
1639+
cmdStartGarbageCollection.overrideNS = overrideNS
16111640
AddBoolFlag(cmdStartGarbageCollection, doctl.ArgGCIncludeUntaggedManifests, "", false,
16121641
"Include untagged manifests in garbage collection.")
16131642
AddBoolFlag(cmdStartGarbageCollection, doctl.ArgGCExcludeUnreferencedBlobs, "", false,
@@ -1636,6 +1665,7 @@ func RegistriesGarbageCollection() *Command {
16361665
aliasOpt("ga", "g"),
16371666
displayerType(&displayers.GarbageCollection{}),
16381667
)
1668+
cmdGetGarbageCollection.overrideNS = overrideNS
16391669
cmdGetGarbageCollection.Example = `The following example retrieves the currently-active garbage collection for a registry named ` + "`" + `example-registry` + "`" + `: doctl registries garbage-collection get-active example-registry`
16401670

16411671
runListGarbageCollectionsDesc := "Retrieves a list of past garbage collections for a registry. Information about each garbage collection includes:" + gcInfoIncluded
@@ -1649,6 +1679,7 @@ func RegistriesGarbageCollection() *Command {
16491679
aliasOpt("ls", "l"),
16501680
displayerType(&displayers.GarbageCollection{}),
16511681
)
1682+
cmdListGarbageCollections.overrideNS = overrideNS
16521683
cmdListGarbageCollections.Example = `The following example retrieves a list of past garbage collections for a registry named ` + "`" + `example-registry` + "`" + `: doctl registries garbage-collection list example-registry`
16531684

16541685
runCancelGarbageCollectionDesc := "Cancels the currently-active garbage collection for a container registry."
@@ -1661,6 +1692,7 @@ func RegistriesGarbageCollection() *Command {
16611692
Writer,
16621693
aliasOpt("c"),
16631694
)
1695+
cmdCancelGarbageCollection.overrideNS = overrideNS
16641696
cmdCancelGarbageCollection.Example = `The following example cancels the garbage collection with the uuid ` + "`" + `gc-uuid` + "`" + ` for a registry named ` + "`" + `example-registry` + "`" + `: doctl registries garbage-collection cancel example-registry gc-uuid`
16651697

16661698
return cmd
@@ -1677,10 +1709,14 @@ func RegistriesOptions() *Command {
16771709
},
16781710
}
16791711

1712+
overrideNS := "registries.options"
1713+
16801714
tiersDesc := "Lists available container registry subscription tiers"
1681-
CmdBuilder(cmd, RunRegistriesOptionsTiers, "subscription-tiers", tiersDesc, tiersDesc, Writer, aliasOpt("tiers"))
1715+
cmdRegistriesOptionsTiers := CmdBuilder(cmd, RunRegistriesOptionsTiers, "subscription-tiers", tiersDesc, tiersDesc, Writer, aliasOpt("tiers"))
1716+
cmdRegistriesOptionsTiers.overrideNS = overrideNS
16821717
regionsDesc := "Lists available container registry regions"
1683-
CmdBuilder(cmd, RunRegistriesOptionsRegions, "available-regions", regionsDesc, regionsDesc, Writer, aliasOpt("regions"))
1718+
cmdRegistriesOptionRegions := CmdBuilder(cmd, RunRegistriesOptionsRegions, "available-regions", regionsDesc, regionsDesc, Writer, aliasOpt("regions"))
1719+
cmdRegistriesOptionRegions.overrideNS = overrideNS
16841720

16851721
return cmd
16861722
}

integration/registry_garbagecollection_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ var _ = suite("registry/garbage-collection", func(t *testing.T, when spec.G, it
217217
"cancel",
218218
)
219219
output, err := cmd.CombinedOutput()
220-
expectMsg := "Error: (garbage-collection.cancel) command is missing required arguments"
220+
// NOTE(13/09/2025) this expected message was changed to have the "registry" prefix because now
221+
// the sub-commands for "registry" and "registries" are distinguished by using overrideNS (override name space)
222+
expectMsg := "Error: (registry.garbage-collection.cancel) command is missing required arguments"
221223
expect.Equal(strings.TrimSpace(expectMsg), strings.TrimSpace(string(output)))
222224
expect.Error(err)
223225
})

0 commit comments

Comments
 (0)