Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions commands/command_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ func overrideCmdNS(ns string) cmdOption {
c.overrideNS = ns
}
}

// WithOverrideNS is a cmdOption that sets the overrideNS for the command.
// This should be used when the overrideNS needs to be set before the command
// is fully built, such as when flags need to be registered with the correct namespace.
func WithOverrideNS(ns string) cmdOption {
return func(c *Command) {
c.overrideNS = ns
}
}
42 changes: 14 additions & 28 deletions commands/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ func Repository() *Command {
cmd,
RunListRepositories, "list",
"List repositories for a container registry", listRepositoriesDesc,
Writer, aliasOpt("ls"), displayerType(&displayers.Repository{}),
Writer, aliasOpt("ls"), WithOverrideNS(overrideNS), displayerType(&displayers.Repository{}),
hiddenCmd(),
)
cmdListRepositories.overrideNS = overrideNS
addRegistryFlag(cmdListRepositories)
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`

Expand All @@ -181,9 +180,8 @@ func Repository() *Command {
cmd,
RunListRepositoriesV2, "list-v2",
"List repositories for a container registry", listRepositoriesV2Desc,
Writer, aliasOpt("ls2"), displayerType(&displayers.Repository{}),
Writer, aliasOpt("ls2"), WithOverrideNS(overrideNS), displayerType(&displayers.Repository{}),
)
cmdListRepositoriesV2.overrideNS = overrideNS
addRegistryFlag(cmdListRepositoriesV2)
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`

Expand All @@ -197,9 +195,8 @@ func Repository() *Command {
cmd,
RunListRepositoryTags, "list-tags <repository>",
"List tags for a repository in a container registry", listRepositoryTagsDesc,
Writer, aliasOpt("lt"), displayerType(&displayers.RepositoryTag{}),
Writer, aliasOpt("lt"), WithOverrideNS(overrideNS), displayerType(&displayers.RepositoryTag{}),
)
cmdListRepositoryTags.overrideNS = overrideNS
addRegistryFlag(cmdListRepositoryTags)
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`

Expand Down Expand Up @@ -230,9 +227,8 @@ func Repository() *Command {
cmd,
RunListRepositoryManifests, "list-manifests <repository>",
"List manifests for a repository in a container registry", listRepositoryManifests,
Writer, aliasOpt("lm"), displayerType(&displayers.RepositoryManifest{}),
Writer, aliasOpt("lm"), WithOverrideNS(overrideNS), displayerType(&displayers.RepositoryManifest{}),
)
cmdListRepositoryManifests.overrideNS = overrideNS
addRegistryFlag(cmdListRepositoryManifests)
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`

Expand Down Expand Up @@ -281,9 +277,8 @@ func GarbageCollection() *Command {
runStartGarbageCollectionDesc,
Writer,
aliasOpt("s"),
displayerType(&displayers.GarbageCollection{}),
WithOverrideNS(overrideNS), displayerType(&displayers.GarbageCollection{}),
)
cmdStartGarbageCollection.overrideNS = overrideNS
AddBoolFlag(cmdStartGarbageCollection, doctl.ArgGCIncludeUntaggedManifests, "", false,
"Include untagged manifests in garbage collection.")
AddBoolFlag(cmdStartGarbageCollection, doctl.ArgGCExcludeUnreferencedBlobs, "", false,
Expand All @@ -310,9 +305,8 @@ func GarbageCollection() *Command {
runGetGarbageCollectionDesc,
Writer,
aliasOpt("ga", "g"),
displayerType(&displayers.GarbageCollection{}),
WithOverrideNS(overrideNS), displayerType(&displayers.GarbageCollection{}),
)
cmdGetGarbageCollection.overrideNS = overrideNS
cmdGetGarbageCollection.Example = `The following example retrieves the currently-active garbage collection for a registry: doctl registry garbage-collection get-active

The following example retrieves the currently-active garbage collection for a registry named ` + "`" + `example-registry` + "`" + `: doctl registry garbage-collection get-active example-registry`
Expand All @@ -326,9 +320,8 @@ The following example retrieves the currently-active garbage collection for a re
runListGarbageCollectionsDesc,
Writer,
aliasOpt("ls", "l"),
displayerType(&displayers.GarbageCollection{}),
WithOverrideNS(overrideNS), displayerType(&displayers.GarbageCollection{}),
)
cmdListGarbageCollections.overrideNS = overrideNS
cmdListGarbageCollections.Example = `The following example retrieves a list of past garbage collections for a registry: doctl registry garbage-collection list

The following example retrieves a list of past garbage collections for a registry named ` + "`" + `example-registry` + "`" + `: doctl registry garbage-collection list example-registry`
Expand Down Expand Up @@ -1527,10 +1520,9 @@ func RegistriesRepository() *Command {
cmd,
RunRegistriesListRepositories, "list <registry-name>",
"List repositories for a container registry", listRepositoriesDesc,
Writer, aliasOpt("ls"), displayerType(&displayers.Repository{}),
Writer, aliasOpt("ls"), WithOverrideNS(overrideNS), displayerType(&displayers.Repository{}),
hiddenCmd(),
)
cmdListRepositories.overrideNS = overrideNS
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`

listRepositoriesV2Desc := `Retrieves information about repositories in a registry, including:
Expand All @@ -1544,9 +1536,8 @@ func RegistriesRepository() *Command {
cmd,
RunRegistriesListRepositoriesV2, "list-v2 <registry-name>",
"List repositories for a container registry", listRepositoriesV2Desc,
Writer, aliasOpt("ls2"), displayerType(&displayers.Repository{}),
Writer, aliasOpt("ls2"), WithOverrideNS(overrideNS), displayerType(&displayers.Repository{}),
)
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`

listRepositoryTagsDesc := `Retrieves information about tags in a repository, including:
Expand All @@ -1559,9 +1550,8 @@ func RegistriesRepository() *Command {
cmd,
RunRegistriesListRepositoryTags, "list-tags <registry-name> <repository>",
"List tags for a repository in a container registry", listRepositoryTagsDesc,
Writer, aliasOpt("lt"), displayerType(&displayers.RepositoryTag{}),
Writer, aliasOpt("lt"), WithOverrideNS(overrideNS), displayerType(&displayers.RepositoryTag{}),
)
cmdListRepositoryTags.overrideNS = overrideNS
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`

deleteTagDesc := "Permanently deletes one or more repository tags."
Expand Down Expand Up @@ -1590,9 +1580,8 @@ func RegistriesRepository() *Command {
cmd,
RunRegistriesListRepositoryManifests, "list-manifests <registry-name> <repository>",
"List manifests for a repository in a container registry", listRepositoryManifests,
Writer, aliasOpt("lm"), displayerType(&displayers.RepositoryManifest{}),
Writer, aliasOpt("lm"), WithOverrideNS(overrideNS), displayerType(&displayers.RepositoryManifest{}),
)
cmdListRepositoryManifests.overrideNS = overrideNS
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`

deleteManifestDesc := "Permanently deletes one or more repository manifests by digest."
Expand Down Expand Up @@ -1634,9 +1623,8 @@ func RegistriesGarbageCollection() *Command {
runStartGarbageCollectionDesc,
Writer,
aliasOpt("s"),
displayerType(&displayers.GarbageCollection{}),
WithOverrideNS(overrideNS), displayerType(&displayers.GarbageCollection{}),
)
cmdStartGarbageCollection.overrideNS = overrideNS
AddBoolFlag(cmdStartGarbageCollection, doctl.ArgGCIncludeUntaggedManifests, "", false,
"Include untagged manifests in garbage collection.")
AddBoolFlag(cmdStartGarbageCollection, doctl.ArgGCExcludeUnreferencedBlobs, "", false,
Expand All @@ -1663,9 +1651,8 @@ func RegistriesGarbageCollection() *Command {
runGetGarbageCollectionDesc,
Writer,
aliasOpt("ga", "g"),
displayerType(&displayers.GarbageCollection{}),
WithOverrideNS(overrideNS), displayerType(&displayers.GarbageCollection{}),
)
cmdGetGarbageCollection.overrideNS = overrideNS
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`

runListGarbageCollectionsDesc := "Retrieves a list of past garbage collections for a registry. Information about each garbage collection includes:" + gcInfoIncluded
Expand All @@ -1677,9 +1664,8 @@ func RegistriesGarbageCollection() *Command {
runListGarbageCollectionsDesc,
Writer,
aliasOpt("ls", "l"),
displayerType(&displayers.GarbageCollection{}),
WithOverrideNS(overrideNS), displayerType(&displayers.GarbageCollection{}),
)
cmdListGarbageCollections.overrideNS = overrideNS
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`

runCancelGarbageCollectionDesc := "Cancels the currently-active garbage collection for a container registry."
Expand Down
36 changes: 36 additions & 0 deletions integration/registry_repo_tag_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,42 @@ var _ = suite("registry/repository/list-tags", func(t *testing.T, when spec.G, i

expect.Equal(strings.TrimSpace(repositoryTagListOutput), strings.TrimSpace(string(output)))
})

it("returns list of repositories in registry with format flag", func() {
cmd := exec.Command(builtBinaryPath,
"-t", "some-magic-token",
"-u", server.URL,
"registry",
"repository",
"list-tags",
"my-repo",
"--format", "Tag",
)

output, err := cmd.CombinedOutput()
expect.NoError(err)

expectedOutput := "Tag\nmy-tag\n"
expect.Equal(expectedOutput, string(output))
})

it("returns list of repositories in registry with no-header flag", func() {
cmd := exec.Command(builtBinaryPath,
"-t", "some-magic-token",
"-u", server.URL,
"registry",
"repository",
"list-tags",
"my-repo",
"--no-header",
)

output, err := cmd.CombinedOutput()
expect.NoError(err)

expectedOutput := "my-tag 1.00 kB 2020-04-01 00:00:00 +0000 UTC sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f\n"
expect.Equal(expectedOutput, string(output))
})
})

var (
Expand Down