summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorKarthik Elango <kelango@redhat.com>2022-07-27 10:43:06 -0400
committerKarthik Elango <kelango@redhat.com>2022-08-04 09:08:14 -0400
commit9964366f69a1fbaa709e45c3d3ebcada283a76b7 (patch)
treef10f06e9e57d59e964f17056edba4f89c1836069 /cmd/podman
parent47a814aa6df97da834315d778cb68f66a82c3231 (diff)
downloadpodman-9964366f69a1fbaa709e45c3d3ebcada283a76b7.tar.gz
podman-9964366f69a1fbaa709e45c3d3ebcada283a76b7.tar.bz2
podman-9964366f69a1fbaa709e45c3d3ebcada283a76b7.zip
start filter flag changes
Tying filtering logic for podman stop and start to same place in getContainersAndInputByContext() to reduce code redundancy Signed-off-by: Karthik Elango <kelango@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/start.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/cmd/podman/containers/start.go b/cmd/podman/containers/start.go
index cd4fa17b8..fc3488e0c 100644
--- a/cmd/podman/containers/start.go
+++ b/cmd/podman/containers/start.go
@@ -59,8 +59,10 @@ func startFlags(cmd *cobra.Command) {
flags.BoolVarP(&startOptions.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached")
flags.BoolVar(&startOptions.SigProxy, "sig-proxy", false, "Proxy received signals to the process (default true if attaching, false otherwise)")
- flags.StringSliceVarP(&filters, "filter", "f", []string{}, "Filter output based on conditions given")
- _ = cmd.RegisterFlagCompletionFunc("filter", common.AutocompletePsFilters)
+
+ filterFlagName := "filter"
+ flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
+ _ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)
flags.BoolVar(&startOptions.All, "all", false, "Start all containers regardless of their state or configuration")
@@ -84,7 +86,7 @@ func init() {
}
func validateStart(cmd *cobra.Command, args []string) error {
- if len(args) == 0 && !startOptions.Latest && !startOptions.All {
+ if len(args) == 0 && !startOptions.Latest && !startOptions.All && len(filters) < 1 {
return errors.New("start requires at least one argument")
}
if startOptions.All && startOptions.Latest {
@@ -123,14 +125,12 @@ func start(cmd *cobra.Command, args []string) error {
}
containers := args
- if len(filters) > 0 {
- for _, f := range filters {
- split := strings.SplitN(f, "=", 2)
- if len(split) == 1 {
- return fmt.Errorf("invalid filter %q", f)
- }
- startOptions.Filters[split[0]] = append(startOptions.Filters[split[0]], split[1])
+ for _, f := range filters {
+ split := strings.SplitN(f, "=", 2)
+ if len(split) < 2 {
+ return fmt.Errorf("invalid filter %q", f)
}
+ startOptions.Filters[split[0]] = append(startOptions.Filters[split[0]], split[1])
}
responses, err := registry.ContainerEngine().ContainerStart(registry.GetContext(), containers, startOptions)