summaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
authorJakub Guzik <jguzik@redhat.com>2021-12-13 11:21:31 +0100
committerJakub Guzik <jguzik@redhat.com>2021-12-14 10:41:03 +0100
commit50501f49a327a2f5c7f1c6746f9fde482c877387 (patch)
tree26781fbc9830785e9442d42378dcb2d0ec9c769a /cmd/podman/common
parent4543fd463e3d02aea42f1a5b6ed0d2ed190de655 (diff)
downloadpodman-50501f49a327a2f5c7f1c6746f9fde482c877387.tar.gz
podman-50501f49a327a2f5c7f1c6746f9fde482c877387.tar.bz2
podman-50501f49a327a2f5c7f1c6746f9fde482c877387.zip
Add secret list --filter to cli
This PR is a follow-up of #11431. It adds possibility of filtering secret list based on id and name. Signed-off-by: Jakub Guzik <jguzik@redhat.com>
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/completion.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index cb3efe592..f26e1d340 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -209,7 +209,7 @@ func getImages(cmd *cobra.Command, toComplete string) ([]string, cobra.ShellComp
return suggestions, cobra.ShellCompDirectiveNoFileComp
}
-func getSecrets(cmd *cobra.Command, toComplete string) ([]string, cobra.ShellCompDirective) {
+func getSecrets(cmd *cobra.Command, toComplete string, cType completeType) ([]string, cobra.ShellCompDirective) {
suggestions := []string{}
engine, err := setupContainerEngine(cmd)
@@ -224,7 +224,13 @@ func getSecrets(cmd *cobra.Command, toComplete string) ([]string, cobra.ShellCom
}
for _, s := range secrets {
- if strings.HasPrefix(s.Spec.Name, toComplete) {
+ // works the same as in getNetworks
+ if ((len(toComplete) > 1 && cType == completeDefault) ||
+ cType == completeIDs) && strings.HasPrefix(s.ID, toComplete) {
+ suggestions = append(suggestions, s.ID[0:12])
+ }
+ // include name in suggestions
+ if cType != completeIDs && strings.HasPrefix(s.Spec.Name, toComplete) {
suggestions = append(suggestions, s.Spec.Name)
}
}
@@ -470,7 +476,7 @@ func AutocompleteSecrets(cmd *cobra.Command, args []string, toComplete string) (
if !validCurrentCmdLine(cmd, args, toComplete) {
return nil, cobra.ShellCompDirectiveNoFileComp
}
- return getSecrets(cmd, toComplete)
+ return getSecrets(cmd, toComplete, completeDefault)
}
func AutocompleteSecretCreate(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
@@ -1283,6 +1289,15 @@ func AutocompleteVolumeFilters(cmd *cobra.Command, args []string, toComplete str
return completeKeyValues(toComplete, kv)
}
+// AutocompleteSecretFilters - Autocomplete secret ls --filter options.
+func AutocompleteSecretFilters(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+ kv := keyValueCompletion{
+ "name=": func(s string) ([]string, cobra.ShellCompDirective) { return getSecrets(cmd, s, completeNames) },
+ "id=": func(s string) ([]string, cobra.ShellCompDirective) { return getSecrets(cmd, s, completeIDs) },
+ }
+ return completeKeyValues(toComplete, kv)
+}
+
// AutocompleteCheckpointCompressType - Autocomplete checkpoint compress type options.
// -> "gzip", "none", "zstd"
func AutocompleteCheckpointCompressType(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {