summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/completion.go27
-rw-r--r--cmd/podman/networks/list.go6
-rw-r--r--cmd/podman/secrets/list.go16
-rw-r--r--cmd/podman/volumes/list.go13
-rw-r--r--cmd/podman/volumes/prune.go3
5 files changed, 50 insertions, 15 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index cb3efe592..f1dea4113 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -13,7 +13,6 @@ import (
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/libpod/network/types"
"github.com/containers/podman/v3/pkg/domain/entities"
- "github.com/containers/podman/v3/pkg/network"
"github.com/containers/podman/v3/pkg/rootless"
systemdDefine "github.com/containers/podman/v3/pkg/systemd/define"
"github.com/containers/podman/v3/pkg/util"
@@ -209,7 +208,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 +223,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)
}
}
@@ -256,12 +261,11 @@ func getNetworks(cmd *cobra.Command, toComplete string, cType completeType) ([]s
}
for _, n := range networks {
- id := network.GetNetworkID(n.Name)
// include ids in suggestions if cType == completeIDs or
// more then 2 chars are typed and cType == completeDefault
if ((len(toComplete) > 1 && cType == completeDefault) ||
- cType == completeIDs) && strings.HasPrefix(id, toComplete) {
- suggestions = append(suggestions, id[0:12])
+ cType == completeIDs) && strings.HasPrefix(n.ID, toComplete) {
+ suggestions = append(suggestions, n.ID[0:12])
}
// include name in suggestions
if cType != completeIDs && strings.HasPrefix(n.Name, toComplete) {
@@ -470,7 +474,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 +1287,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) {
diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go
index 6f1a7742a..7ce566225 100644
--- a/cmd/podman/networks/list.go
+++ b/cmd/podman/networks/list.go
@@ -3,6 +3,7 @@ package network
import (
"fmt"
"os"
+ "sort"
"strings"
"github.com/containers/common/pkg/completion"
@@ -73,6 +74,11 @@ func networkList(cmd *cobra.Command, args []string) error {
return err
}
+ // sort the networks to make sure the order is deterministic
+ sort.Slice(responses, func(i, j int) bool {
+ return responses[i].Name < responses[j].Name
+ })
+
switch {
// quiet means we only print the network names
case networkListOptions.Quiet:
diff --git a/cmd/podman/secrets/list.go b/cmd/podman/secrets/list.go
index 255d9ae1a..2074ab973 100644
--- a/cmd/podman/secrets/list.go
+++ b/cmd/podman/secrets/list.go
@@ -8,6 +8,7 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
"github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/pkg/domain/entities"
@@ -32,6 +33,7 @@ var (
type listFlagType struct {
format string
noHeading bool
+ filter []string
}
func init() {
@@ -44,14 +46,26 @@ func init() {
formatFlagName := "format"
flags.StringVar(&listFlag.format, formatFlagName, "{{.ID}}\t{{.Name}}\t{{.Driver}}\t{{.CreatedAt}}\t{{.UpdatedAt}}\t\n", "Format volume output using Go template")
_ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(entities.SecretInfoReport{}))
+ filterFlagName := "filter"
+ flags.StringSliceVarP(&listFlag.filter, filterFlagName, "f", []string{}, "Filter secret output")
+ _ = lsCmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteSecretFilters)
flags.BoolVar(&listFlag.noHeading, "noheading", false, "Do not print headers")
}
func ls(cmd *cobra.Command, args []string) error {
- responses, err := registry.ContainerEngine().SecretList(context.Background(), entities.SecretListRequest{})
+ var err error
+ lsOpts := entities.SecretListRequest{}
+
+ lsOpts.Filters, err = parse.FilterArgumentsIntoFilters(listFlag.filter)
+ if err != nil {
+ return err
+ }
+
+ responses, err := registry.ContainerEngine().SecretList(context.Background(), lsOpts)
if err != nil {
return err
}
+
listed := make([]*entities.SecretListReport, 0, len(responses))
for _, response := range responses {
listed = append(listed, &entities.SecretListReport{
diff --git a/cmd/podman/volumes/list.go b/cmd/podman/volumes/list.go
index c372527de..97fa2c61f 100644
--- a/cmd/podman/volumes/list.go
+++ b/cmd/podman/volumes/list.go
@@ -4,11 +4,11 @@ import (
"context"
"fmt"
"os"
- "strings"
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
"github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
"github.com/containers/podman/v3/libpod/define"
@@ -64,19 +64,18 @@ func init() {
}
func list(cmd *cobra.Command, args []string) error {
+ var err error
if cliOpts.Quiet && cmd.Flag("format").Changed {
return errors.New("quiet and format flags cannot be used together")
}
if len(cliOpts.Filter) > 0 {
lsOpts.Filter = make(map[string][]string)
}
- for _, f := range cliOpts.Filter {
- filterSplit := strings.SplitN(f, "=", 2)
- if len(filterSplit) < 2 {
- return errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
- }
- lsOpts.Filter[filterSplit[0]] = append(lsOpts.Filter[filterSplit[0]], filterSplit[1])
+ lsOpts.Filter, err = parse.FilterArgumentsIntoFilters(cliOpts.Filter)
+ if err != nil {
+ return err
}
+
responses, err := registry.ContainerEngine().VolumeList(context.Background(), lsOpts)
if err != nil {
return err
diff --git a/cmd/podman/volumes/prune.go b/cmd/podman/volumes/prune.go
index 1f3cc6913..43b529768 100644
--- a/cmd/podman/volumes/prune.go
+++ b/cmd/podman/volumes/prune.go
@@ -58,6 +58,9 @@ func prune(cmd *cobra.Command, args []string) error {
return err
}
pruneOptions.Filters, err = parse.FilterArgumentsIntoFilters(filter)
+ if err != nil {
+ return err
+ }
if !force {
reader := bufio.NewReader(os.Stdin)
fmt.Println("WARNING! This will remove all volumes not used by at least one container. The following volumes will be removed:")