Merge pull request #6716 from jwhonce/issues/6598

Fixes --remote flag issues
This commit is contained in:
OpenShift Merge Robot
2020-06-29 11:31:39 -04:00
committed by GitHub
60 changed files with 400 additions and 459 deletions

View File

@ -44,10 +44,6 @@ func attachFlags(flags *pflag.FlagSet) {
flags.StringVar(&attachOpts.DetachKeys, "detach-keys", containerConfig.DetachKeys(), "Select the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-z`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`") flags.StringVar(&attachOpts.DetachKeys, "detach-keys", containerConfig.DetachKeys(), "Select the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-z`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`")
flags.BoolVar(&attachOpts.NoStdin, "no-stdin", false, "Do not attach STDIN. The default is false") flags.BoolVar(&attachOpts.NoStdin, "no-stdin", false, "Do not attach STDIN. The default is false")
flags.BoolVar(&attachOpts.SigProxy, "sig-proxy", true, "Proxy received signals to the process") flags.BoolVar(&attachOpts.SigProxy, "sig-proxy", true, "Proxy received signals to the process")
flags.BoolVarP(&attachOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func init() { func init() {
@ -55,22 +51,24 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: attachCommand, Command: attachCommand,
}) })
flags := attachCommand.Flags() attachFlags(attachCommand.Flags())
attachFlags(flags) validate.AddLatestFlag(attachCommand, &attachOpts.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerAttachCommand, Command: containerAttachCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
containerAttachFlags := containerAttachCommand.Flags() attachFlags(containerAttachCommand.Flags())
attachFlags(containerAttachFlags) validate.AddLatestFlag(containerAttachCommand, &attachOpts.Latest)
} }
func attach(cmd *cobra.Command, args []string) error { func attach(cmd *cobra.Command, args []string) error {
if len(args) > 1 || (len(args) == 0 && !attachOpts.Latest) { if len(args) > 1 || (len(args) == 0 && !attachOpts.Latest) {
return errors.Errorf("attach requires the name or id of one running container or the latest flag") return errors.Errorf("attach requires the name or id of one running container or the latest flag")
} }
var name string var name string
if len(args) > 0 { if len(args) > 0 {
name = args[0] name = args[0]

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/rootless" "github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -25,7 +25,7 @@ var (
Long: checkpointDescription, Long: checkpointDescription,
RunE: checkpoint, RunE: checkpoint,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman container checkpoint --keep ctrID Example: `podman container checkpoint --keep ctrID
podman container checkpoint --all podman container checkpoint --all
@ -48,12 +48,9 @@ func init() {
flags.BoolVarP(&checkpointOptions.LeaveRunning, "leave-running", "R", false, "Leave the container running after writing checkpoint to disk") flags.BoolVarP(&checkpointOptions.LeaveRunning, "leave-running", "R", false, "Leave the container running after writing checkpoint to disk")
flags.BoolVar(&checkpointOptions.TCPEstablished, "tcp-established", false, "Checkpoint a container with established TCP connections") flags.BoolVar(&checkpointOptions.TCPEstablished, "tcp-established", false, "Checkpoint a container with established TCP connections")
flags.BoolVarP(&checkpointOptions.All, "all", "a", false, "Checkpoint all running containers") flags.BoolVarP(&checkpointOptions.All, "all", "a", false, "Checkpoint all running containers")
flags.BoolVarP(&checkpointOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.StringVarP(&checkpointOptions.Export, "export", "e", "", "Export the checkpoint image to a tar.gz") flags.StringVarP(&checkpointOptions.Export, "export", "e", "", "Export the checkpoint image to a tar.gz")
flags.BoolVar(&checkpointOptions.IgnoreRootFS, "ignore-rootfs", false, "Do not include root file-system changes when exporting") flags.BoolVar(&checkpointOptions.IgnoreRootFS, "ignore-rootfs", false, "Do not include root file-system changes when exporting")
if registry.IsRemote() { validate.AddLatestFlag(checkpointCommand, &checkpointOptions.Latest)
_ = flags.MarkHidden("latest")
}
} }
func checkpoint(cmd *cobra.Command, args []string) error { func checkpoint(cmd *cobra.Command, args []string) error {

View File

@ -3,9 +3,9 @@ package containers
import ( import (
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -24,7 +24,7 @@ var (
Long: cleanupDescription, Long: cleanupDescription,
RunE: cleanup, RunE: cleanup,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman container cleanup --latest Example: `podman container cleanup --latest
podman container cleanup ctrID1 ctrID2 ctrID3 podman container cleanup ctrID1 ctrID2 ctrID3
@ -44,11 +44,10 @@ func init() {
}) })
flags := cleanupCommand.Flags() flags := cleanupCommand.Flags()
flags.BoolVarP(&cleanupOptions.All, "all", "a", false, "Cleans up all containers") flags.BoolVarP(&cleanupOptions.All, "all", "a", false, "Cleans up all containers")
flags.BoolVarP(&cleanupOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.StringVar(&cleanupOptions.Exec, "exec", "", "Clean up the given exec session instead of the container") flags.StringVar(&cleanupOptions.Exec, "exec", "", "Clean up the given exec session instead of the container")
flags.BoolVar(&cleanupOptions.Remove, "rm", false, "After cleanup, remove the container entirely") flags.BoolVar(&cleanupOptions.Remove, "rm", false, "After cleanup, remove the container entirely")
flags.BoolVar(&cleanupOptions.RemoveImage, "rmi", false, "After cleanup, remove the image entirely") flags.BoolVar(&cleanupOptions.RemoveImage, "rmi", false, "After cleanup, remove the image entirely")
validate.AddLatestFlag(cleanupCommand, &cleanupOptions.Latest)
} }
func cleanup(cmd *cobra.Command, args []string) error { func cleanup(cmd *cobra.Command, args []string) error {

View File

@ -58,6 +58,7 @@ func createFlags(flags *pflag.FlagSet) {
flags.AddFlagSet(common.GetCreateFlags(&cliVals)) flags.AddFlagSet(common.GetCreateFlags(&cliVals))
flags.AddFlagSet(common.GetNetFlags()) flags.AddFlagSet(common.GetNetFlags())
flags.SetNormalizeFunc(common.AliasFlags) flags.SetNormalizeFunc(common.AliasFlags)
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("authfile") _ = flags.MarkHidden("authfile")
_ = flags.MarkHidden("env-host") _ = flags.MarkHidden("env-host")

View File

@ -14,8 +14,8 @@ var (
diffCmd = &cobra.Command{ diffCmd = &cobra.Command{
Use: "diff [flags] CONTAINER", Use: "diff [flags] CONTAINER",
Args: validate.IDOrLatestArgs, Args: validate.IDOrLatestArgs,
Short: "Inspect changes on container's file systems", Short: "Inspect changes to the container's file systems",
Long: `Displays changes on a container filesystem. The container will be compared to its parent layer.`, Long: `Displays changes to the container filesystem's'. The container will be compared to its parent layer.`,
RunE: diff, RunE: diff,
Example: `podman container diff myCtr Example: `podman container diff myCtr
podman container diff -l --format json myCtr`, podman container diff -l --format json myCtr`,
@ -35,10 +35,7 @@ func init() {
flags.BoolVar(&diffOpts.Archive, "archive", true, "Save the diff as a tar archive") flags.BoolVar(&diffOpts.Archive, "archive", true, "Save the diff as a tar archive")
_ = flags.MarkHidden("archive") _ = flags.MarkHidden("archive")
flags.StringVar(&diffOpts.Format, "format", "", "Change the output format") flags.StringVar(&diffOpts.Format, "format", "", "Change the output format")
validate.AddLatestFlag(diffCmd, &diffOpts.Latest)
if !registry.IsRemote() {
flags.BoolVarP(&diffOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
}
} }
func diff(cmd *cobra.Command, args []string) error { func diff(cmd *cobra.Command, args []string) error {

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
envLib "github.com/containers/libpod/pkg/env" envLib "github.com/containers/libpod/pkg/env"
@ -53,14 +54,13 @@ func execFlags(flags *pflag.FlagSet) {
flags.StringArrayVarP(&envInput, "env", "e", []string{}, "Set environment variables") flags.StringArrayVarP(&envInput, "env", "e", []string{}, "Set environment variables")
flags.StringSliceVar(&envFile, "env-file", []string{}, "Read in a file of environment variables") flags.StringSliceVar(&envFile, "env-file", []string{}, "Read in a file of environment variables")
flags.BoolVarP(&execOpts.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached") flags.BoolVarP(&execOpts.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached")
flags.BoolVarP(&execOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&execOpts.Privileged, "privileged", false, "Give the process extended Linux capabilities inside the container. The default is false") flags.BoolVar(&execOpts.Privileged, "privileged", false, "Give the process extended Linux capabilities inside the container. The default is false")
flags.BoolVarP(&execOpts.Tty, "tty", "t", false, "Allocate a pseudo-TTY. The default is false") flags.BoolVarP(&execOpts.Tty, "tty", "t", false, "Allocate a pseudo-TTY. The default is false")
flags.StringVarP(&execOpts.User, "user", "u", "", "Sets the username or UID used and optionally the groupname or GID for the specified command") flags.StringVarP(&execOpts.User, "user", "u", "", "Sets the username or UID used and optionally the groupname or GID for the specified command")
flags.UintVar(&execOpts.PreserveFDs, "preserve-fds", 0, "Pass N additional file descriptors to the container") flags.UintVar(&execOpts.PreserveFDs, "preserve-fds", 0, "Pass N additional file descriptors to the container")
flags.StringVarP(&execOpts.WorkDir, "workdir", "w", "", "Working directory inside the container") flags.StringVarP(&execOpts.WorkDir, "workdir", "w", "", "Working directory inside the container")
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("preserve-fds") _ = flags.MarkHidden("preserve-fds")
} }
} }
@ -70,20 +70,19 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: execCommand, Command: execCommand,
}) })
flags := execCommand.Flags() execFlags(execCommand.Flags())
execFlags(flags) validate.AddLatestFlag(execCommand, &execOpts.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerExecCommand, Command: containerExecCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
execFlags(containerExecCommand.Flags())
containerExecFlags := containerExecCommand.Flags() validate.AddLatestFlag(containerExecCommand, &execOpts.Latest)
execFlags(containerExecFlags)
} }
func exec(cmd *cobra.Command, args []string) error { func exec(_ *cobra.Command, args []string) error {
var nameOrID string var nameOrID string
if len(args) == 0 && !execOpts.Latest { if len(args) == 0 && !execOpts.Latest {

View File

@ -3,9 +3,9 @@ package containers
import ( import (
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -20,7 +20,7 @@ var (
Long: initDescription, Long: initDescription,
RunE: initContainer, RunE: initContainer,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman init --latest Example: `podman init --latest
podman init 3c45ef19d893 podman init 3c45ef19d893
@ -45,10 +45,6 @@ var (
func initFlags(flags *pflag.FlagSet) { func initFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&initOptions.All, "all", "a", false, "Initialize all containers") flags.BoolVarP(&initOptions.All, "all", "a", false, "Initialize all containers")
flags.BoolVarP(&initOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func init() { func init() {
@ -58,15 +54,16 @@ func init() {
}) })
flags := initCommand.Flags() flags := initCommand.Flags()
initFlags(flags) initFlags(flags)
validate.AddLatestFlag(initCommand, &initOptions.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Parent: containerCmd, Parent: containerCmd,
Command: containerInitCommand, Command: containerInitCommand,
}) })
containerInitFlags := containerInitCommand.Flags() containerInitFlags := containerInitCommand.Flags()
initFlags(containerInitFlags) initFlags(containerInitFlags)
validate.AddLatestFlag(containerInitCommand, &initOptions.Latest)
} }
func initContainer(cmd *cobra.Command, args []string) error { func initContainer(cmd *cobra.Command, args []string) error {

View File

@ -3,6 +3,7 @@ package containers
import ( import (
"github.com/containers/libpod/cmd/podman/inspect" "github.com/containers/libpod/cmd/podman/inspect"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -30,7 +31,7 @@ func init() {
flags := inspectCmd.Flags() flags := inspectCmd.Flags()
flags.BoolVarP(&inspectOpts.Size, "size", "s", false, "Display total file size") flags.BoolVarP(&inspectOpts.Size, "size", "s", false, "Display total file size")
flags.StringVarP(&inspectOpts.Format, "format", "f", "json", "Format the output to a Go template or json") flags.StringVarP(&inspectOpts.Format, "format", "f", "json", "Format the output to a Go template or json")
flags.BoolVarP(&inspectOpts.Latest, "latest", "l", false, "Act on the latest container Podman is aware of") validate.AddLatestFlag(inspectCmd, &inspectOpts.Latest)
} }
func inspectExec(cmd *cobra.Command, args []string) error { func inspectExec(cmd *cobra.Command, args []string) error {

View File

@ -5,9 +5,9 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/signal" "github.com/containers/libpod/pkg/signal"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -22,7 +22,7 @@ var (
Long: killDescription, Long: killDescription,
RunE: kill, RunE: kill,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman kill mywebserver Example: `podman kill mywebserver
podman kill 860a4b23 podman kill 860a4b23
@ -31,7 +31,7 @@ var (
containerKillCommand = &cobra.Command{ containerKillCommand = &cobra.Command{
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Use: killCommand.Use, Use: killCommand.Use,
Short: killCommand.Short, Short: killCommand.Short,
@ -50,10 +50,6 @@ var (
func killFlags(flags *pflag.FlagSet) { func killFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&killOptions.All, "all", "a", false, "Signal all running containers") flags.BoolVarP(&killOptions.All, "all", "a", false, "Signal all running containers")
flags.StringVarP(&killOptions.Signal, "signal", "s", "KILL", "Signal to send to the container") flags.StringVarP(&killOptions.Signal, "signal", "s", "KILL", "Signal to send to the container")
flags.BoolVarP(&killOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func init() { func init() {
@ -61,20 +57,19 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: killCommand, Command: killCommand,
}) })
flags := killCommand.Flags() killFlags(killCommand.Flags())
killFlags(flags) validate.AddLatestFlag(killCommand, &killOptions.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerKillCommand, Command: containerKillCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
killFlags(containerKillCommand.Flags())
containerKillFlags := containerKillCommand.Flags() validate.AddLatestFlag(containerKillCommand, &killOptions.Latest)
killFlags(containerKillFlags)
} }
func kill(cmd *cobra.Command, args []string) error { func kill(_ *cobra.Command, args []string) error {
var ( var (
err error err error
errs utils.OutputErrors errs utils.OutputErrors

View File

@ -29,4 +29,5 @@ func init() {
Parent: containerCmd, Parent: containerCmd,
}) })
listFlagSet(listCmd.Flags()) listFlagSet(listCmd.Flags())
validate.AddLatestFlag(listCmd, &listOpts.Latest)
} }

View File

@ -4,6 +4,7 @@ import (
"os" "os"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/util" "github.com/containers/libpod/pkg/util"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -68,9 +69,8 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: logsCommand, Command: logsCommand,
}) })
logsFlags(logsCommand.Flags())
flags := logsCommand.Flags() validate.AddLatestFlag(logsCommand, &logsOptions.Latest)
logsFlags(flags)
// container logs // container logs
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
@ -78,15 +78,13 @@ func init() {
Command: containerLogsCommand, Command: containerLogsCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
logsFlags(containerLogsCommand.Flags())
containerLogsFlags := containerLogsCommand.Flags() validate.AddLatestFlag(containerLogsCommand, &logsOptions.Latest)
logsFlags(containerLogsFlags)
} }
func logsFlags(flags *pflag.FlagSet) { func logsFlags(flags *pflag.FlagSet) {
flags.BoolVar(&logsOptions.Details, "details", false, "Show extra details provided to the logs") flags.BoolVar(&logsOptions.Details, "details", false, "Show extra details provided to the logs")
flags.BoolVarP(&logsOptions.Follow, "follow", "f", false, "Follow log output. The default is false") flags.BoolVarP(&logsOptions.Follow, "follow", "f", false, "Follow log output. The default is false")
flags.BoolVarP(&logsOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.StringVar(&logsOptions.SinceRaw, "since", "", "Show logs since TIMESTAMP") flags.StringVar(&logsOptions.SinceRaw, "since", "", "Show logs since TIMESTAMP")
flags.Int64Var(&logsOptions.Tail, "tail", -1, "Output the specified number of LINES at the end of the logs. Defaults to -1, which prints all lines") flags.Int64Var(&logsOptions.Tail, "tail", -1, "Output the specified number of LINES at the end of the logs. Defaults to -1, which prints all lines")
flags.BoolVarP(&logsOptions.Timestamps, "timestamps", "t", false, "Output the timestamps in the log") flags.BoolVarP(&logsOptions.Timestamps, "timestamps", "t", false, "Output the timestamps in the log")
@ -95,7 +93,7 @@ func logsFlags(flags *pflag.FlagSet) {
_ = flags.MarkHidden("details") _ = flags.MarkHidden("details")
} }
func logs(cmd *cobra.Command, args []string) error { func logs(_ *cobra.Command, args []string) error {
if logsOptions.SinceRaw != "" { if logsOptions.SinceRaw != "" {
// parse time, error out if something is wrong // parse time, error out if something is wrong
since, err := util.ParseInputTime(logsOptions.SinceRaw) since, err := util.ParseInputTime(logsOptions.SinceRaw)

View File

@ -6,9 +6,9 @@ import (
"text/tabwriter" "text/tabwriter"
"text/template" "text/template"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -28,7 +28,7 @@ var (
Long: mountDescription, Long: mountDescription,
RunE: mount, RunE: mount,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, true, false) return validate.CheckAllLatestAndCIDFile(cmd, args, true, false)
}, },
} }
@ -47,7 +47,6 @@ var (
func mountFlags(flags *pflag.FlagSet) { func mountFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&mountOpts.All, "all", "a", false, "Mount all containers") flags.BoolVarP(&mountOpts.All, "all", "a", false, "Mount all containers")
flags.StringVar(&mountOpts.Format, "format", "", "Change the output format to Go template") flags.StringVar(&mountOpts.Format, "format", "", "Change the output format to Go template")
flags.BoolVarP(&mountOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&mountOpts.NoTruncate, "notruncate", false, "Do not truncate output") flags.BoolVar(&mountOpts.NoTruncate, "notruncate", false, "Do not truncate output")
} }
@ -56,19 +55,19 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode}, Mode: []entities.EngineMode{entities.ABIMode},
Command: mountCommand, Command: mountCommand,
}) })
flags := mountCommand.Flags() mountFlags(mountCommand.Flags())
mountFlags(flags) validate.AddLatestFlag(mountCommand, &mountOpts.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode}, Mode: []entities.EngineMode{entities.ABIMode},
Command: containerMountCommmand, Command: containerMountCommmand,
Parent: containerCmd, Parent: containerCmd,
}) })
containerMountFlags := containerMountCommmand.Flags() mountFlags(containerMountCommmand.Flags())
mountFlags(containerMountFlags) validate.AddLatestFlag(containerMountCommmand, &mountOpts.Latest)
} }
func mount(cmd *cobra.Command, args []string) error { func mount(_ *cobra.Command, args []string) error {
var ( var (
errs utils.OutputErrors errs utils.OutputErrors
) )

View File

@ -66,6 +66,7 @@ func pause(cmd *cobra.Command, args []string) error {
if rootless.IsRootless() && !registry.IsRemote() { if rootless.IsRootless() && !registry.IsRemote() {
return errors.New("pause is not supported for rootless containers") return errors.New("pause is not supported for rootless containers")
} }
if len(args) < 1 && !pauseOpts.All { if len(args) < 1 && !pauseOpts.All {
return errors.Errorf("you must provide at least one container name or id") return errors.Errorf("you must provide at least one container name or id")
} }

View File

@ -5,8 +5,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/cri-o/ocicni/pkg/ocicni" "github.com/cri-o/ocicni/pkg/ocicni"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -23,7 +23,7 @@ var (
Long: portDescription, Long: portDescription,
RunE: port, RunE: port,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, true, false) return validate.CheckAllLatestAndCIDFile(cmd, args, true, false)
}, },
Example: `podman port --all Example: `podman port --all
podman port ctrID 80/tcp podman port ctrID 80/tcp
@ -36,7 +36,7 @@ var (
Long: portDescription, Long: portDescription,
RunE: portCommand.RunE, RunE: portCommand.RunE,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, true, false) return validate.CheckAllLatestAndCIDFile(cmd, args, true, false)
}, },
Example: `podman container port --all Example: `podman container port --all
podman container port --latest 80`, podman container port --latest 80`,
@ -49,10 +49,6 @@ var (
func portFlags(flags *pflag.FlagSet) { func portFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&portOpts.All, "all", "a", false, "Display port information for all containers") flags.BoolVarP(&portOpts.All, "all", "a", false, "Display port information for all containers")
flags.BoolVarP(&portOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func init() { func init() {
@ -60,22 +56,19 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: portCommand, Command: portCommand,
}) })
portFlags(portCommand.Flags())
flags := portCommand.Flags() validate.AddLatestFlag(portCommand, &portOpts.Latest)
portFlags(flags)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerPortCommand, Command: containerPortCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
portFlags(containerPortCommand.Flags())
containerPortflags := containerPortCommand.Flags() validate.AddLatestFlag(containerPortCommand, &portOpts.Latest)
portFlags(containerPortflags)
} }
func port(cmd *cobra.Command, args []string) error { func port(_ *cobra.Command, args []string) error {
var ( var (
container string container string
err error err error

View File

@ -50,6 +50,7 @@ func init() {
Command: psCommand, Command: psCommand,
}) })
listFlagSet(psCommand.Flags()) listFlagSet(psCommand.Flags())
validate.AddLatestFlag(psCommand, &listOpts.Latest)
} }
func listFlagSet(flags *pflag.FlagSet) { func listFlagSet(flags *pflag.FlagSet) {
@ -57,7 +58,6 @@ func listFlagSet(flags *pflag.FlagSet) {
flags.StringSliceVarP(&filters, "filter", "f", []string{}, "Filter output based on conditions given") flags.StringSliceVarP(&filters, "filter", "f", []string{}, "Filter output based on conditions given")
flags.StringVar(&listOpts.Format, "format", "", "Pretty-print containers to JSON or using a Go template") flags.StringVar(&listOpts.Format, "format", "", "Pretty-print containers to JSON or using a Go template")
flags.IntVarP(&listOpts.Last, "last", "n", -1, "Print the n last created containers (all states)") flags.IntVarP(&listOpts.Last, "last", "n", -1, "Print the n last created containers (all states)")
flags.BoolVarP(&listOpts.Latest, "latest", "l", false, "Show the latest container created (all states)")
flags.BoolVar(&listOpts.Namespace, "namespace", false, "Display namespace information") flags.BoolVar(&listOpts.Namespace, "namespace", false, "Display namespace information")
flags.BoolVar(&listOpts.Namespace, "ns", false, "Display namespace information") flags.BoolVar(&listOpts.Namespace, "ns", false, "Display namespace information")
flags.BoolVar(&noTrunc, "no-trunc", false, "Display the extended information") flags.BoolVar(&noTrunc, "no-trunc", false, "Display the extended information")
@ -69,10 +69,6 @@ func listFlagSet(flags *pflag.FlagSet) {
sort := validate.Value(&listOpts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status") sort := validate.Value(&listOpts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status")
flags.Var(sort, "sort", "Sort output by: "+sort.Choices()) flags.Var(sort, "sort", "Sort output by: "+sort.Choices())
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func checkFlags(c *cobra.Command) error { func checkFlags(c *cobra.Command) error {
// latest, and last are mutually exclusive. // latest, and last are mutually exclusive.

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -25,7 +25,7 @@ var (
Long: restartDescription, Long: restartDescription,
RunE: restart, RunE: restart,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman restart ctrID Example: `podman restart ctrID
podman restart --latest podman restart --latest
@ -50,12 +50,9 @@ var (
func restartFlags(flags *pflag.FlagSet) { func restartFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&restartOptions.All, "all", "a", false, "Restart all non-running containers") flags.BoolVarP(&restartOptions.All, "all", "a", false, "Restart all non-running containers")
flags.BoolVarP(&restartOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&restartOptions.Running, "running", false, "Restart only running containers when --all is used") flags.BoolVar(&restartOptions.Running, "running", false, "Restart only running containers when --all is used")
flags.UintVarP(&restartTimeout, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for stop before killing the container") flags.UintVarP(&restartTimeout, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for stop before killing the container")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
flags.SetNormalizeFunc(utils.AliasFlags) flags.SetNormalizeFunc(utils.AliasFlags)
} }
@ -64,17 +61,16 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: restartCommand, Command: restartCommand,
}) })
flags := restartCommand.Flags() restartFlags(restartCommand.Flags())
restartFlags(flags) validate.AddLatestFlag(restartCommand, &restartOptions.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerRestartCommand, Command: containerRestartCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
restartFlags(containerRestartCommand.Flags())
containerRestartFlags := containerRestartCommand.Flags() validate.AddLatestFlag(containerRestartCommand, &restartOptions.Latest)
restartFlags(containerRestartFlags)
} }
func restart(cmd *cobra.Command, args []string) error { func restart(cmd *cobra.Command, args []string) error {

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/rootless" "github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -25,7 +25,7 @@ var (
Long: restoreDescription, Long: restoreDescription,
RunE: restore, RunE: restore,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, true, false) return validate.CheckAllLatestAndCIDFile(cmd, args, true, false)
}, },
Example: `podman container restore ctrID Example: `podman container restore ctrID
podman container restore --latest podman container restore --latest
@ -46,19 +46,16 @@ func init() {
flags := restoreCommand.Flags() flags := restoreCommand.Flags()
flags.BoolVarP(&restoreOptions.All, "all", "a", false, "Restore all checkpointed containers") flags.BoolVarP(&restoreOptions.All, "all", "a", false, "Restore all checkpointed containers")
flags.BoolVarP(&restoreOptions.Keep, "keep", "k", false, "Keep all temporary checkpoint files") flags.BoolVarP(&restoreOptions.Keep, "keep", "k", false, "Keep all temporary checkpoint files")
flags.BoolVarP(&restoreOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&restoreOptions.TCPEstablished, "tcp-established", false, "Restore a container with established TCP connections") flags.BoolVar(&restoreOptions.TCPEstablished, "tcp-established", false, "Restore a container with established TCP connections")
flags.StringVarP(&restoreOptions.Import, "import", "i", "", "Restore from exported checkpoint archive (tar.gz)") flags.StringVarP(&restoreOptions.Import, "import", "i", "", "Restore from exported checkpoint archive (tar.gz)")
flags.StringVarP(&restoreOptions.Name, "name", "n", "", "Specify new name for container restored from exported checkpoint (only works with --import)") flags.StringVarP(&restoreOptions.Name, "name", "n", "", "Specify new name for container restored from exported checkpoint (only works with --import)")
flags.BoolVar(&restoreOptions.IgnoreRootFS, "ignore-rootfs", false, "Do not apply root file-system changes when importing from exported checkpoint") flags.BoolVar(&restoreOptions.IgnoreRootFS, "ignore-rootfs", false, "Do not apply root file-system changes when importing from exported checkpoint")
flags.BoolVar(&restoreOptions.IgnoreStaticIP, "ignore-static-ip", false, "Ignore IP address set via --static-ip") flags.BoolVar(&restoreOptions.IgnoreStaticIP, "ignore-static-ip", false, "Ignore IP address set via --static-ip")
flags.BoolVar(&restoreOptions.IgnoreStaticMAC, "ignore-static-mac", false, "Ignore MAC address set via --mac-address") flags.BoolVar(&restoreOptions.IgnoreStaticMAC, "ignore-static-mac", false, "Ignore MAC address set via --mac-address")
if registry.IsRemote() { validate.AddLatestFlag(restoreCommand, &restoreOptions.Latest)
_ = flags.MarkHidden("latest")
}
} }
func restore(cmd *cobra.Command, args []string) error { func restore(_ *cobra.Command, args []string) error {
var errs utils.OutputErrors var errs utils.OutputErrors
if rootless.IsRootless() { if rootless.IsRootless() {
return errors.New("restoring a container requires root") return errors.New("restoring a container requires root")

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -26,7 +26,7 @@ var (
Long: rmDescription, Long: rmDescription,
RunE: rm, RunE: rm,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, true) return validate.CheckAllLatestAndCIDFile(cmd, args, false, true)
}, },
Example: `podman rm imageID Example: `podman rm imageID
podman rm mywebserver myflaskserver 860a4b23 podman rm mywebserver myflaskserver 860a4b23
@ -40,7 +40,7 @@ var (
Long: rmCommand.Long, Long: rmCommand.Long,
RunE: rmCommand.RunE, RunE: rmCommand.RunE,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, true) return validate.CheckAllLatestAndCIDFile(cmd, args, false, true)
}, },
Example: `podman container rm imageID Example: `podman container rm imageID
podman container rm mywebserver myflaskserver 860a4b23 podman container rm mywebserver myflaskserver 860a4b23
@ -57,12 +57,11 @@ func rmFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all containers") flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all containers")
flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing") flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing")
flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Force removal of a running or unusable container. The default is false") flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Force removal of a running or unusable container. The default is false")
flags.BoolVarP(&rmOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&rmOptions.Storage, "storage", false, "Remove container from storage library") flags.BoolVar(&rmOptions.Storage, "storage", false, "Remove container from storage library")
flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container") flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container")
flags.StringArrayVarP(&rmOptions.CIDFiles, "cidfile", "", nil, "Read the container ID from the file") flags.StringArrayVarP(&rmOptions.CIDFiles, "cidfile", "", nil, "Read the container ID from the file")
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore") _ = flags.MarkHidden("ignore")
_ = flags.MarkHidden("cidfile") _ = flags.MarkHidden("cidfile")
_ = flags.MarkHidden("storage") _ = flags.MarkHidden("storage")
@ -75,18 +74,18 @@ func init() {
Command: rmCommand, Command: rmCommand,
}) })
rmFlags(rmCommand.Flags()) rmFlags(rmCommand.Flags())
validate.AddLatestFlag(rmCommand, &rmOptions.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerRmCommand, Command: containerRmCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
rmFlags(containerRmCommand.Flags())
containerRmFlags := containerRmCommand.Flags() validate.AddLatestFlag(containerRmCommand, &rmOptions.Latest)
rmFlags(containerRmFlags)
} }
func rm(cmd *cobra.Command, args []string) error { func rm(_ *cobra.Command, args []string) error {
return removeContainers(args, rmOptions, true) return removeContainers(args, rmOptions, true)
} }

View File

@ -62,6 +62,7 @@ func runFlags(flags *pflag.FlagSet) {
flags.BoolVar(&runOpts.SigProxy, "sig-proxy", true, "Proxy received signals to the process") flags.BoolVar(&runOpts.SigProxy, "sig-proxy", true, "Proxy received signals to the process")
flags.BoolVar(&runRmi, "rmi", false, "Remove container image unless used by other containers") flags.BoolVar(&runRmi, "rmi", false, "Remove container image unless used by other containers")
flags.UintVar(&runOpts.PreserveFDs, "preserve-fds", 0, "Pass a number of additional file descriptors into the container") flags.UintVar(&runOpts.PreserveFDs, "preserve-fds", 0, "Pass a number of additional file descriptors into the container")
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("authfile") _ = flags.MarkHidden("authfile")
_ = flags.MarkHidden("env-host") _ = flags.MarkHidden("env-host")

View File

@ -6,6 +6,7 @@ import (
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -44,10 +45,9 @@ func startFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&startOptions.Attach, "attach", "a", false, "Attach container's STDOUT and STDERR") flags.BoolVarP(&startOptions.Attach, "attach", "a", false, "Attach container's STDOUT and STDERR")
flags.StringVar(&startOptions.DetachKeys, "detach-keys", containerConfig.DetachKeys(), "Select the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-z`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`") flags.StringVar(&startOptions.DetachKeys, "detach-keys", containerConfig.DetachKeys(), "Select the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-z`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`")
flags.BoolVarP(&startOptions.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached") flags.BoolVarP(&startOptions.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached")
flags.BoolVarP(&startOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.BoolVar(&startOptions.SigProxy, "sig-proxy", false, "Proxy received signals to the process (default true if attaching, false otherwise)") flags.BoolVar(&startOptions.SigProxy, "sig-proxy", false, "Proxy received signals to the process (default true if attaching, false otherwise)")
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("sig-proxy") _ = flags.MarkHidden("sig-proxy")
} }
} }
@ -56,17 +56,17 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: startCommand, Command: startCommand,
}) })
flags := startCommand.Flags() startFlags(startCommand.Flags())
startFlags(flags) validate.AddLatestFlag(startCommand, &startOptions.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerStartCommand, Command: containerStartCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
startFlags(containerStartCommand.Flags())
validate.AddLatestFlag(containerStartCommand, &startOptions.Latest)
containerStartFlags := containerStartCommand.Flags()
startFlags(containerStartFlags)
} }
func start(cmd *cobra.Command, args []string) error { func start(cmd *cobra.Command, args []string) error {

View File

@ -10,6 +10,7 @@ import (
tm "github.com/buger/goterm" tm "github.com/buger/goterm"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/cgroups" "github.com/containers/libpod/pkg/cgroups"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
@ -56,12 +57,8 @@ var (
func statFlags(flags *pflag.FlagSet) { func statFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&statsOptions.All, "all", "a", false, "Show all containers. Only running containers are shown by default. The default is false") flags.BoolVarP(&statsOptions.All, "all", "a", false, "Show all containers. Only running containers are shown by default. The default is false")
flags.StringVar(&statsOptions.Format, "format", "", "Pretty-print container statistics to JSON or using a Go template") flags.StringVar(&statsOptions.Format, "format", "", "Pretty-print container statistics to JSON or using a Go template")
flags.BoolVarP(&statsOptions.Latest, "latest", "l", false, "Act on the latest container Podman is aware of")
flags.BoolVar(&statsOptions.NoReset, "no-reset", false, "Disable resetting the screen between intervals") flags.BoolVar(&statsOptions.NoReset, "no-reset", false, "Disable resetting the screen between intervals")
flags.BoolVar(&statsOptions.NoStream, "no-stream", false, "Disable streaming stats and only pull the first result, default setting is false") flags.BoolVar(&statsOptions.NoStream, "no-stream", false, "Disable streaming stats and only pull the first result, default setting is false")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func init() { func init() {
@ -69,17 +66,16 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: statsCommand, Command: statsCommand,
}) })
flags := statsCommand.Flags() statFlags(statsCommand.Flags())
statFlags(flags) validate.AddLatestFlag(statsCommand, &statsOptions.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerStatsCommand, Command: containerStatsCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
statFlags(containerStatsCommand.Flags())
containerStatsFlags := containerStatsCommand.Flags() validate.AddLatestFlag(containerStatsCommand, &statsOptions.Latest)
statFlags(containerStatsFlags)
} }
// stats is different in that it will assume running containers if // stats is different in that it will assume running containers if

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -22,7 +22,7 @@ var (
Long: stopDescription, Long: stopDescription,
RunE: stop, RunE: stop,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, true) return validate.CheckAllLatestAndCIDFile(cmd, args, false, true)
}, },
Example: `podman stop ctrID Example: `podman stop ctrID
podman stop --latest podman stop --latest
@ -35,7 +35,7 @@ var (
Long: stopCommand.Long, Long: stopCommand.Long,
RunE: stopCommand.RunE, RunE: stopCommand.RunE,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, true) return validate.CheckAllLatestAndCIDFile(cmd, args, false, true)
}, },
Example: `podman container stop ctrID Example: `podman container stop ctrID
podman container stop --latest podman container stop --latest
@ -52,11 +52,9 @@ func stopFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&stopOptions.All, "all", "a", false, "Stop all running containers") flags.BoolVarP(&stopOptions.All, "all", "a", false, "Stop all running containers")
flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing") flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing")
flags.StringArrayVarP(&stopOptions.CIDFiles, "cidfile", "", nil, "Read the container ID from the file") flags.StringArrayVarP(&stopOptions.CIDFiles, "cidfile", "", nil, "Read the container ID from the file")
flags.BoolVarP(&stopOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.UintVarP(&stopTimeout, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for stop before killing the container") flags.UintVarP(&stopTimeout, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for stop before killing the container")
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("cidfile") _ = flags.MarkHidden("cidfile")
_ = flags.MarkHidden("ignore") _ = flags.MarkHidden("ignore")
} }
@ -68,8 +66,8 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: stopCommand, Command: stopCommand,
}) })
flags := stopCommand.Flags() stopFlags(stopCommand.Flags())
stopFlags(flags) validate.AddLatestFlag(stopCommand, &stopOptions.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
@ -77,8 +75,8 @@ func init() {
Parent: containerCmd, Parent: containerCmd,
}) })
containerStopFlags := containerStopCommand.Flags() stopFlags(containerStopCommand.Flags())
stopFlags(containerStopFlags) validate.AddLatestFlag(containerStopCommand, &stopOptions.Latest)
} }
func stop(cmd *cobra.Command, args []string) error { func stop(cmd *cobra.Command, args []string) error {

View File

@ -8,6 +8,7 @@ import (
"text/tabwriter" "text/tabwriter"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/util" "github.com/containers/libpod/pkg/util"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -51,11 +52,7 @@ podman container top ctrID -eo user,pid,comm`,
func topFlags(flags *pflag.FlagSet) { func topFlags(flags *pflag.FlagSet) {
flags.SetInterspersed(false) flags.SetInterspersed(false)
flags.BoolVar(&topOptions.ListDescriptors, "list-descriptors", false, "") flags.BoolVar(&topOptions.ListDescriptors, "list-descriptors", false, "")
flags.BoolVarP(&topOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
_ = flags.MarkHidden("list-descriptors") // meant only for bash completion _ = flags.MarkHidden("list-descriptors") // meant only for bash completion
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func init() { func init() {
@ -63,8 +60,8 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: topCommand, Command: topCommand,
}) })
flags := topCommand.Flags() topFlags(topCommand.Flags())
topFlags(flags) validate.AddLatestFlag(topCommand, &topOptions.Latest)
descriptors, err := util.GetContainerPidInformationDescriptors() descriptors, err := util.GetContainerPidInformationDescriptors()
if err == nil { if err == nil {
@ -77,8 +74,8 @@ func init() {
Command: containerTopCommand, Command: containerTopCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
containerTopFlags := containerTopCommand.Flags() topFlags(containerTopCommand.Flags())
topFlags(containerTopFlags) validate.AddLatestFlag(containerTopCommand, &topOptions.Latest)
} }
func top(cmd *cobra.Command, args []string) error { func top(cmd *cobra.Command, args []string) error {

View File

@ -3,9 +3,9 @@ package containers
import ( import (
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -25,7 +25,7 @@ var (
Long: description, Long: description,
RunE: unmount, RunE: unmount,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman umount ctrID Example: `podman umount ctrID
podman umount ctrID1 ctrID2 ctrID3 podman umount ctrID1 ctrID2 ctrID3
@ -38,7 +38,7 @@ var (
Long: umountCommand.Long, Long: umountCommand.Long,
RunE: umountCommand.RunE, RunE: umountCommand.RunE,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman container umount ctrID Example: `podman container umount ctrID
podman container umount ctrID1 ctrID2 ctrID3 podman container umount ctrID1 ctrID2 ctrID3
@ -53,7 +53,6 @@ var (
func umountFlags(flags *pflag.FlagSet) { func umountFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&unmountOpts.All, "all", "a", false, "Umount all of the currently mounted containers") flags.BoolVarP(&unmountOpts.All, "all", "a", false, "Umount all of the currently mounted containers")
flags.BoolVarP(&unmountOpts.Force, "force", "f", false, "Force the complete umount all of the currently mounted containers") flags.BoolVarP(&unmountOpts.Force, "force", "f", false, "Force the complete umount all of the currently mounted containers")
flags.BoolVarP(&unmountOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
} }
func init() { func init() {
@ -61,17 +60,16 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode}, Mode: []entities.EngineMode{entities.ABIMode},
Command: umountCommand, Command: umountCommand,
}) })
flags := umountCommand.Flags() umountFlags(umountCommand.Flags())
umountFlags(flags) validate.AddLatestFlag(umountCommand, &unmountOpts.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode}, Mode: []entities.EngineMode{entities.ABIMode},
Command: containerUnmountCommand, Command: containerUnmountCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
umountFlags(containerUnmountCommand.Flags())
containerUmountFlags := containerUnmountCommand.Flags() validate.AddLatestFlag(containerUnmountCommand, &unmountOpts.Latest)
umountFlags(containerUmountFlags)
} }
func unmount(cmd *cobra.Command, args []string) error { func unmount(cmd *cobra.Command, args []string) error {

View File

@ -47,9 +47,6 @@ var (
func waitFlags(flags *pflag.FlagSet) { func waitFlags(flags *pflag.FlagSet) {
flags.DurationVarP(&waitOptions.Interval, "interval", "i", time.Duration(250), "Milliseconds to wait before polling for completion") flags.DurationVarP(&waitOptions.Interval, "interval", "i", time.Duration(250), "Milliseconds to wait before polling for completion")
flags.StringVar(&waitCondition, "condition", "stopped", "Condition to wait on") flags.StringVar(&waitCondition, "condition", "stopped", "Condition to wait on")
if !registry.IsRemote() {
flags.BoolVarP(&waitOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
}
} }
func init() { func init() {
@ -57,17 +54,17 @@ func init() {
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: waitCommand, Command: waitCommand,
}) })
flags := waitCommand.Flags() waitFlags(waitCommand.Flags())
waitFlags(flags) validate.AddLatestFlag(waitCommand, &waitOptions.Latest)
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerWaitCommand, Command: containerWaitCommand,
Parent: containerCmd, Parent: containerCmd,
}) })
waitFlags(containerWaitCommand.Flags())
validate.AddLatestFlag(containerWaitCommand, &waitOptions.Latest)
containerWaitFlags := containerWaitCommand.Flags()
waitFlags(containerWaitFlags)
} }
func wait(cmd *cobra.Command, args []string) error { func wait(cmd *cobra.Command, args []string) error {

View File

@ -17,12 +17,11 @@ var (
// Command: podman _diff_ Object_ID // Command: podman _diff_ Object_ID
diffDescription = `Displays changes on a container or image's filesystem. The container or image will be compared to its parent layer.` diffDescription = `Displays changes on a container or image's filesystem. The container or image will be compared to its parent layer.`
diffCmd = &cobra.Command{ diffCmd = &cobra.Command{
Use: "diff [flags] {CONTAINER_ID | IMAGE_ID}", Use: "diff [flags] {CONTAINER_ID | IMAGE_ID}",
Args: validate.IDOrLatestArgs, Args: validate.IDOrLatestArgs,
Short: "Display the changes of object's file system", Short: "Display the changes to the object's file system",
Long: diffDescription, Long: diffDescription,
TraverseChildren: true, RunE: diff,
RunE: diff,
Example: `podman diff imageID Example: `podman diff imageID
podman diff ctrID podman diff ctrID
podman diff --format json redis:alpine`, podman diff --format json redis:alpine`,
@ -40,10 +39,7 @@ func init() {
flags.BoolVar(&diffOpts.Archive, "archive", true, "Save the diff as a tar archive") flags.BoolVar(&diffOpts.Archive, "archive", true, "Save the diff as a tar archive")
_ = flags.MarkHidden("archive") _ = flags.MarkHidden("archive")
flags.StringVar(&diffOpts.Format, "format", "", "Change the output format") flags.StringVar(&diffOpts.Format, "format", "", "Change the output format")
validate.AddLatestFlag(diffCmd, &diffOpts.Latest)
if !registry.IsRemote() {
flags.BoolVarP(&diffOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
}
} }
func diff(cmd *cobra.Command, args []string) error { func diff(cmd *cobra.Command, args []string) error {

View File

@ -11,11 +11,10 @@ import (
var ( var (
// Command: podman _generate_ // Command: podman _generate_
generateCmd = &cobra.Command{ generateCmd = &cobra.Command{
Use: "generate", Use: "generate",
Short: "Generate structured data based on containers and pods.", Short: "Generate structured data based on containers and pods.",
Long: "Generate structured data (e.g., Kubernetes yaml or systemd units) based on containers and pods.", Long: "Generate structured data (e.g., Kubernetes yaml or systemd units) based on containers and pods.",
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
} }
containerConfig = util.DefaultContainerConfig() containerConfig = util.DefaultContainerConfig()
) )

View File

@ -10,11 +10,10 @@ import (
var ( var (
// Command: healthcheck // Command: healthcheck
healthCmd = &cobra.Command{ healthCmd = &cobra.Command{
Use: "healthcheck", Use: "healthcheck",
Short: "Manage health checks on containers", Short: "Manage health checks on containers",
Long: "Run health checks on containers", Long: "Run health checks on containers",
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
} }
) )

View File

@ -40,12 +40,11 @@ var (
// Command: podman _diff_ Object_ID // Command: podman _diff_ Object_ID
buildDescription = "Builds an OCI or Docker image using instructions from one or more Containerfiles and a specified build context directory." buildDescription = "Builds an OCI or Docker image using instructions from one or more Containerfiles and a specified build context directory."
buildCmd = &cobra.Command{ buildCmd = &cobra.Command{
Use: "build [flags] [CONTEXT]", Use: "build [flags] [CONTEXT]",
Short: "Build an image using instructions from Containerfiles", Short: "Build an image using instructions from Containerfiles",
Long: buildDescription, Long: buildDescription,
TraverseChildren: true, Args: cobra.MaximumNArgs(1),
RunE: build, RunE: build,
Args: cobra.MaximumNArgs(1),
Example: `podman build . Example: `podman build .
podman build --creds=username:password -t imageName -f Containerfile.simple . podman build --creds=username:password -t imageName -f Containerfile.simple .
podman build --layers --force-rm --tag imageName .`, podman build --layers --force-rm --tag imageName .`,

View File

@ -14,8 +14,8 @@ var (
diffCmd = &cobra.Command{ diffCmd = &cobra.Command{
Use: "diff [flags] IMAGE", Use: "diff [flags] IMAGE",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
Short: "Inspect changes on image's file systems", Short: "Inspect changes to the image's file systems",
Long: `Displays changes on a image's filesystem. The image will be compared to its parent layer.`, Long: `Displays changes to the image's filesystem. The image will be compared to its parent layer.`,
RunE: diff, RunE: diff,
Example: `podman image diff myImage Example: `podman image diff myImage
podman image diff --format json redis:alpine`, podman image diff --format json redis:alpine`,

View File

@ -13,11 +13,10 @@ var (
// Command: podman _image_ // Command: podman _image_
imageCmd = &cobra.Command{ imageCmd = &cobra.Command{
Use: "image", Use: "image",
Short: "Manage images", Short: "Manage images",
Long: "Manage images", Long: "Manage images",
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
} }
) )

View File

@ -86,6 +86,7 @@ func searchFlags(flags *pflag.FlagSet) {
flags.BoolVar(&searchOptions.NoTrunc, "no-trunc", false, "Do not truncate the output") flags.BoolVar(&searchOptions.NoTrunc, "no-trunc", false, "Do not truncate the output")
flags.StringVar(&searchOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override") flags.StringVar(&searchOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
flags.BoolVar(&searchOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries") flags.BoolVar(&searchOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("authfile") _ = flags.MarkHidden("authfile")
_ = flags.MarkHidden("tls-verify") _ = flags.MarkHidden("tls-verify")

View File

@ -10,11 +10,10 @@ import (
var ( var (
// Command: podman _inspect_ Object_ID // Command: podman _inspect_ Object_ID
inspectCmd = &cobra.Command{ inspectCmd = &cobra.Command{
Use: "inspect [flags] {CONTAINER_ID | IMAGE_ID} [...]", Use: "inspect [flags] {CONTAINER_ID | IMAGE_ID} [...]",
Short: "Display the configuration of object denoted by ID", Short: "Display the configuration of object denoted by ID",
Long: "Displays the low-level information on an object identified by name or ID", Long: "Displays the low-level information on an object identified by name or ID",
TraverseChildren: true, RunE: inspectExec,
RunE: inspectExec,
Example: `podman inspect fedora Example: `podman inspect fedora
podman inspect --type image fedora podman inspect --type image fedora
podman inspect CtrID ImgID podman inspect CtrID ImgID

View File

@ -8,6 +8,7 @@ import (
"github.com/containers/buildah/pkg/formats" "github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -32,8 +33,8 @@ func AddInspectFlagSet(cmd *cobra.Command) *entities.InspectOptions {
flags.BoolVarP(&opts.Size, "size", "s", false, "Display total file size") flags.BoolVarP(&opts.Size, "size", "s", false, "Display total file size")
flags.StringVarP(&opts.Format, "format", "f", "json", "Format the output to a Go template or json") flags.StringVarP(&opts.Format, "format", "f", "json", "Format the output to a Go template or json")
flags.StringVarP(&opts.Type, "type", "t", AllType, fmt.Sprintf("Specify inspect-oject type (%q, %q or %q)", ImageType, ContainerType, AllType)) flags.StringVarP(&opts.Type, "type", "t", AllType, fmt.Sprintf("Specify inspect-oject type (%q, %q or %q)", ImageType, ContainerType, AllType))
flags.BoolVarP(&opts.Latest, "latest", "l", false, "Act on the latest container Podman is aware of")
validate.AddLatestFlag(cmd, &opts.Latest)
return &opts return &opts
} }

View File

@ -10,11 +10,10 @@ import (
var ( var (
manifestDescription = "Creates, modifies, and pushes manifest lists and image indexes." manifestDescription = "Creates, modifies, and pushes manifest lists and image indexes."
manifestCmd = &cobra.Command{ manifestCmd = &cobra.Command{
Use: "manifest", Use: "manifest",
Short: "Manipulate manifest lists and image indexes", Short: "Manipulate manifest lists and image indexes",
Long: manifestDescription, Long: manifestDescription,
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
Example: `podman manifest add mylist:v1.11 image:v1.11-amd64 Example: `podman manifest add mylist:v1.11 image:v1.11-amd64
podman manifest create localhost/list podman manifest create localhost/list
podman manifest inspect localhost/list podman manifest inspect localhost/list

View File

@ -49,6 +49,7 @@ func init() {
flags.StringVar(&manifestPushOpts.SignBy, "sign-by", "", "sign the image using a GPG key with the specified `FINGERPRINT`") flags.StringVar(&manifestPushOpts.SignBy, "sign-by", "", "sign the image using a GPG key with the specified `FINGERPRINT`")
flags.BoolVar(&manifestPushOpts.TLSVerifyCLI, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry") flags.BoolVar(&manifestPushOpts.TLSVerifyCLI, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry")
flags.BoolVarP(&manifestPushOpts.Quiet, "quiet", "q", false, "don't output progress information when pushing lists") flags.BoolVarP(&manifestPushOpts.Quiet, "quiet", "q", false, "don't output progress information when pushing lists")
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("authfile") _ = flags.MarkHidden("authfile")
_ = flags.MarkHidden("cert-dir") _ = flags.MarkHidden("cert-dir")

View File

@ -10,11 +10,10 @@ import (
var ( var (
// Command: podman _network_ // Command: podman _network_
networkCmd = &cobra.Command{ networkCmd = &cobra.Command{
Use: "network", Use: "network",
Short: "Manage networks", Short: "Manage networks",
Long: "Manage networks", Long: "Manage networks",
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
} }
) )

View File

@ -1,112 +0,0 @@
package parse
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
// TODO: the two functions here are almost identical. It may be worth looking
// into generalizing the two a bit more and share code but time is scarce and
// we only live once.
// CheckAllLatestAndCIDFile checks that --all and --latest are used correctly.
// If cidfile is set, also check for the --cidfile flag.
func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool, cidfile bool) error {
argLen := len(args)
if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
if !cidfile {
return errors.New("unable to lookup values for 'latest' or 'all'")
} else if c.Flags().Lookup("cidfile") == nil {
return errors.New("unable to lookup values for 'latest', 'all' or 'cidfile'")
}
}
specifiedAll, _ := c.Flags().GetBool("all")
specifiedLatest, _ := c.Flags().GetBool("latest")
specifiedCIDFile := false
if cid, _ := c.Flags().GetStringArray("cidfile"); len(cid) > 0 {
specifiedCIDFile = true
}
if specifiedCIDFile && (specifiedAll || specifiedLatest) {
return errors.Errorf("--all, --latest and --cidfile cannot be used together")
} else if specifiedAll && specifiedLatest {
return errors.Errorf("--all and --latest cannot be used together")
}
if (argLen > 0) && specifiedAll {
return errors.Errorf("no arguments are needed with --all")
}
if ignoreArgLen {
return nil
}
if argLen > 0 {
if specifiedLatest {
return errors.Errorf("no arguments are needed with --latest")
} else if cidfile && (specifiedLatest || specifiedCIDFile) {
return errors.Errorf("no arguments are needed with --latest or --cidfile")
}
}
if specifiedCIDFile {
return nil
}
if argLen < 1 && !specifiedAll && !specifiedLatest && !specifiedCIDFile {
return errors.Errorf("you must provide at least one name or id")
}
return nil
}
// CheckAllLatestAndPodIDFile checks that --all and --latest are used correctly.
// If withIDFile is set, also check for the --pod-id-file flag.
func CheckAllLatestAndPodIDFile(c *cobra.Command, args []string, ignoreArgLen bool, withIDFile bool) error {
argLen := len(args)
if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
if !withIDFile {
return errors.New("unable to lookup values for 'latest' or 'all'")
} else if c.Flags().Lookup("pod-id-file") == nil {
return errors.New("unable to lookup values for 'latest', 'all' or 'pod-id-file'")
}
}
specifiedAll, _ := c.Flags().GetBool("all")
specifiedLatest, _ := c.Flags().GetBool("latest")
specifiedPodIDFile := false
if pid, _ := c.Flags().GetStringArray("pod-id-file"); len(pid) > 0 {
specifiedPodIDFile = true
}
if specifiedPodIDFile && (specifiedAll || specifiedLatest) {
return errors.Errorf("--all, --latest and --pod-id-file cannot be used together")
} else if specifiedAll && specifiedLatest {
return errors.Errorf("--all and --latest cannot be used together")
}
if (argLen > 0) && specifiedAll {
return errors.Errorf("no arguments are needed with --all")
}
if ignoreArgLen {
return nil
}
if argLen > 0 {
if specifiedLatest {
return errors.Errorf("no arguments are needed with --latest")
} else if withIDFile && (specifiedLatest || specifiedPodIDFile) {
return errors.Errorf("no arguments are needed with --latest or --pod-id-file")
}
}
if specifiedPodIDFile {
return nil
}
if argLen < 1 && !specifiedAll && !specifiedLatest && !specifiedPodIDFile {
return errors.Errorf("you must provide at least one name or id")
}
return nil
}

View File

@ -61,7 +61,6 @@ func init() {
flags.StringVar(&kubeOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)") flags.StringVar(&kubeOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
flags.StringVar(&kubeOptions.SeccompProfileRoot, "seccomp-profile-root", defaultSeccompRoot, "Directory path for seccomp profiles") flags.StringVar(&kubeOptions.SeccompProfileRoot, "seccomp-profile-root", defaultSeccompRoot, "Directory path for seccomp profiles")
} }
_ = flags.MarkHidden("signature-policy") _ = flags.MarkHidden("signature-policy")
} }

View File

@ -10,11 +10,10 @@ import (
var ( var (
// Command: podman _play_ // Command: podman _play_
playCmd = &cobra.Command{ playCmd = &cobra.Command{
Use: "play", Use: "play",
Short: "Play a pod and its containers from a structured file.", Short: "Play a pod and its containers from a structured file.",
Long: "Play structured data (e.g., Kubernetes pod or service yaml) based on containers and pods.", Long: "Play structured data (e.g., Kubernetes pod or service yaml) based on containers and pods.",
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
} }
) )

View File

@ -6,6 +6,7 @@ import (
"github.com/containers/buildah/pkg/formats" "github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -36,11 +37,8 @@ func init() {
Parent: podCmd, Parent: podCmd,
}) })
flags := inspectCmd.Flags() flags := inspectCmd.Flags()
flags.BoolVarP(&inspectOptions.Latest, "latest", "l", false, "Act on the latest pod podman is aware of")
flags.StringVarP(&inspectOptions.Format, "format", "f", "json", "Format the output to a Go template or json") flags.StringVarP(&inspectOptions.Format, "format", "f", "json", "Format the output to a Go template or json")
if registry.IsRemote() { validate.AddLatestFlag(inspectCmd, &inspectOptions.Latest)
_ = flags.MarkHidden("latest")
}
} }
func inspect(cmd *cobra.Command, args []string) error { func inspect(cmd *cobra.Command, args []string) error {

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -21,7 +21,7 @@ var (
Long: podKillDescription, Long: podKillDescription,
RunE: kill, RunE: kill,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman pod kill podID Example: `podman pod kill podID
podman pod kill --signal TERM mywebserver podman pod kill --signal TERM mywebserver
@ -41,14 +41,11 @@ func init() {
}) })
flags := killCommand.Flags() flags := killCommand.Flags()
flags.BoolVarP(&killOpts.All, "all", "a", false, "Kill all containers in all pods") flags.BoolVarP(&killOpts.All, "all", "a", false, "Kill all containers in all pods")
flags.BoolVarP(&killOpts.Latest, "latest", "l", false, "Act on the latest pod podman is aware of")
flags.StringVarP(&killOpts.Signal, "signal", "s", "KILL", "Signal to send to the containers in the pod") flags.StringVarP(&killOpts.Signal, "signal", "s", "KILL", "Signal to send to the containers in the pod")
if registry.IsRemote() { validate.AddLatestFlag(killCommand, &killOpts.Latest)
_ = flags.MarkHidden("latest")
}
} }
func kill(cmd *cobra.Command, args []string) error {
func kill(_ *cobra.Command, args []string) error {
var ( var (
errs utils.OutputErrors errs utils.OutputErrors
) )

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -21,7 +21,7 @@ var (
Long: podPauseDescription, Long: podPauseDescription,
RunE: pause, RunE: pause,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman pod pause podID1 podID2 Example: `podman pod pause podID1 podID2
podman pod pause --latest podman pod pause --latest
@ -41,12 +41,9 @@ func init() {
}) })
flags := pauseCommand.Flags() flags := pauseCommand.Flags()
flags.BoolVarP(&pauseOptions.All, "all", "a", false, "Pause all running pods") flags.BoolVarP(&pauseOptions.All, "all", "a", false, "Pause all running pods")
flags.BoolVarP(&pauseOptions.Latest, "latest", "l", false, "Act on the latest pod podman is aware of") validate.AddLatestFlag(pauseCommand, &pauseOptions.Latest)
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func pause(cmd *cobra.Command, args []string) error { func pause(_ *cobra.Command, args []string) error {
var ( var (
errs utils.OutputErrors errs utils.OutputErrors
) )

View File

@ -14,11 +14,10 @@ var (
// Command: podman _pod_ // Command: podman _pod_
podCmd = &cobra.Command{ podCmd = &cobra.Command{
Use: "pod", Use: "pod",
Short: "Manage pods", Short: "Manage pods",
Long: "Pods are a group of one or more containers sharing the same network, pid and ipc namespaces.", Long: "Pods are a group of one or more containers sharing the same network, pid and ipc namespaces.",
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
} }
containerConfig = util.DefaultContainerConfig() containerConfig = util.DefaultContainerConfig()
) )

View File

@ -53,18 +53,15 @@ func init() {
// TODO should we make this a [] ? // TODO should we make this a [] ?
flags.StringSliceVarP(&inputFilters, "filter", "f", []string{}, "Filter output based on conditions given") flags.StringSliceVarP(&inputFilters, "filter", "f", []string{}, "Filter output based on conditions given")
flags.StringVar(&psInput.Format, "format", "", "Pretty-print pods to JSON or using a Go template") flags.StringVar(&psInput.Format, "format", "", "Pretty-print pods to JSON or using a Go template")
flags.BoolVarP(&psInput.Latest, "latest", "l", false, "Act on the latest pod podman is aware of")
flags.BoolVar(&psInput.Namespace, "namespace", false, "Display namespace information of the pod") flags.BoolVar(&psInput.Namespace, "namespace", false, "Display namespace information of the pod")
flags.BoolVar(&psInput.Namespace, "ns", false, "Display namespace information of the pod") flags.BoolVar(&psInput.Namespace, "ns", false, "Display namespace information of the pod")
flags.BoolVar(&noTrunc, "no-trunc", false, "Do not truncate pod and container IDs") flags.BoolVar(&noTrunc, "no-trunc", false, "Do not truncate pod and container IDs")
flags.BoolVarP(&psInput.Quiet, "quiet", "q", false, "Print the numeric IDs of the pods only") flags.BoolVarP(&psInput.Quiet, "quiet", "q", false, "Print the numeric IDs of the pods only")
flags.StringVar(&psInput.Sort, "sort", "created", "Sort output by created, id, name, or number") flags.StringVar(&psInput.Sort, "sort", "created", "Sort output by created, id, name, or number")
if registry.IsRemote() { validate.AddLatestFlag(psCmd, &psInput.Latest)
_ = flags.MarkHidden("latest")
}
} }
func pods(cmd *cobra.Command, args []string) error { func pods(cmd *cobra.Command, _ []string) error {
var ( var (
w io.Writer = os.Stdout w io.Writer = os.Stdout
row string row string

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -21,7 +21,7 @@ var (
Long: podRestartDescription, Long: podRestartDescription,
RunE: restart, RunE: restart,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman pod restart podID1 podID2 Example: `podman pod restart podID1 podID2
podman pod restart --latest podman pod restart --latest
@ -42,10 +42,7 @@ func init() {
flags := restartCommand.Flags() flags := restartCommand.Flags()
flags.BoolVarP(&restartOptions.All, "all", "a", false, "Restart all running pods") flags.BoolVarP(&restartOptions.All, "all", "a", false, "Restart all running pods")
flags.BoolVarP(&restartOptions.Latest, "latest", "l", false, "Restart the latest pod podman is aware of") validate.AddLatestFlag(restartCommand, &restartOptions.Latest)
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func restart(cmd *cobra.Command, args []string) error { func restart(cmd *cobra.Command, args []string) error {

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/common" "github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -30,7 +30,7 @@ var (
Long: podRmDescription, Long: podRmDescription,
RunE: rm, RunE: rm,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true) return validate.CheckAllLatestAndPodIDFile(cmd, args, false, true)
}, },
Example: `podman pod rm mywebserverpod Example: `podman pod rm mywebserverpod
podman pod rm -f 860a4b23 podman pod rm -f 860a4b23
@ -49,15 +49,15 @@ func init() {
flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all running pods") flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all running pods")
flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Force removal of a running pod by first stopping all containers, then removing all containers in the pod. The default is false") flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Force removal of a running pod by first stopping all containers, then removing all containers in the pod. The default is false")
flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing") flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing")
flags.BoolVarP(&rmOptions.Latest, "latest", "l", false, "Remove the latest pod podman is aware of")
flags.StringArrayVarP(&rmOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file") flags.StringArrayVarP(&rmOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
validate.AddLatestFlag(rmCommand, &rmOptions.Latest)
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore") _ = flags.MarkHidden("ignore")
} }
} }
func rm(cmd *cobra.Command, args []string) error { func rm(_ *cobra.Command, args []string) error {
ids, err := common.ReadPodIDFiles(rmOptions.PodIDFiles) ids, err := common.ReadPodIDFiles(rmOptions.PodIDFiles)
if err != nil { if err != nil {
return err return err

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/common" "github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -29,7 +29,7 @@ var (
Long: podStartDescription, Long: podStartDescription,
RunE: start, RunE: start,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true) return validate.CheckAllLatestAndPodIDFile(cmd, args, false, true)
}, },
Example: `podman pod start podID Example: `podman pod start podID
podman pod start --latest podman pod start --latest
@ -50,11 +50,8 @@ func init() {
flags := startCommand.Flags() flags := startCommand.Flags()
flags.BoolVarP(&startOptions.All, "all", "a", false, "Restart all running pods") flags.BoolVarP(&startOptions.All, "all", "a", false, "Restart all running pods")
flags.BoolVarP(&startOptions.Latest, "latest", "l", false, "Restart the latest pod podman is aware of")
flags.StringArrayVarP(&startOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file") flags.StringArrayVarP(&startOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
if registry.IsRemote() { validate.AddLatestFlag(startCommand, &startOptions.Latest)
_ = flags.MarkHidden("latest")
}
} }
func start(cmd *cobra.Command, args []string) error { func start(cmd *cobra.Command, args []string) error {

View File

@ -13,6 +13,7 @@ import (
"github.com/buger/goterm" "github.com/buger/goterm"
"github.com/containers/buildah/pkg/formats" "github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/util/camelcase" "github.com/containers/libpod/pkg/util/camelcase"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -55,13 +56,9 @@ func init() {
flags := statsCmd.Flags() flags := statsCmd.Flags()
flags.BoolVarP(&statsOptions.All, "all", "a", false, "Provide stats for all pods") flags.BoolVarP(&statsOptions.All, "all", "a", false, "Provide stats for all pods")
flags.StringVar(&statsOptions.Format, "format", "", "Pretty-print container statistics to JSON or using a Go template") flags.StringVar(&statsOptions.Format, "format", "", "Pretty-print container statistics to JSON or using a Go template")
flags.BoolVarP(&statsOptions.Latest, "latest", "l", false, "Provide stats on the latest pod Podman is aware of")
flags.BoolVar(&statsOptions.NoReset, "no-reset", false, "Disable resetting the screen when streaming") flags.BoolVar(&statsOptions.NoReset, "no-reset", false, "Disable resetting the screen when streaming")
flags.BoolVar(&statsOptions.NoStream, "no-stream", false, "Disable streaming stats and only pull the first result") flags.BoolVar(&statsOptions.NoStream, "no-stream", false, "Disable streaming stats and only pull the first result")
validate.AddLatestFlag(statsCmd, &statsOptions.Latest)
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func stats(cmd *cobra.Command, args []string) error { func stats(cmd *cobra.Command, args []string) error {

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/common" "github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -34,7 +34,7 @@ var (
Long: podStopDescription, Long: podStopDescription,
RunE: stop, RunE: stop,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true) return validate.CheckAllLatestAndPodIDFile(cmd, args, false, true)
}, },
Example: `podman pod stop mywebserverpod Example: `podman pod stop mywebserverpod
podman pod stop --latest podman pod stop --latest
@ -51,13 +51,14 @@ func init() {
flags := stopCommand.Flags() flags := stopCommand.Flags()
flags.BoolVarP(&stopOptions.All, "all", "a", false, "Stop all running pods") flags.BoolVarP(&stopOptions.All, "all", "a", false, "Stop all running pods")
flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing") flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing")
flags.BoolVarP(&stopOptions.Latest, "latest", "l", false, "Stop the latest pod podman is aware of")
flags.UintVarP(&stopOptions.TimeoutCLI, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for pod stop before killing the container") flags.UintVarP(&stopOptions.TimeoutCLI, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for pod stop before killing the container")
flags.StringArrayVarP(&stopOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file") flags.StringArrayVarP(&stopOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
validate.AddLatestFlag(stopCommand, &stopOptions.Latest)
if registry.IsRemote() { if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore") _ = flags.MarkHidden("ignore")
} }
flags.SetNormalizeFunc(utils.AliasFlags) flags.SetNormalizeFunc(utils.AliasFlags)
} }

View File

@ -8,6 +8,7 @@ import (
"text/tabwriter" "text/tabwriter"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/util" "github.com/containers/libpod/pkg/util"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -50,15 +51,11 @@ func init() {
flags := topCommand.Flags() flags := topCommand.Flags()
flags.SetInterspersed(false) flags.SetInterspersed(false)
flags.BoolVar(&topOptions.ListDescriptors, "list-descriptors", false, "") flags.BoolVar(&topOptions.ListDescriptors, "list-descriptors", false, "")
flags.BoolVarP(&topOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
_ = flags.MarkHidden("list-descriptors") // meant only for bash completion _ = flags.MarkHidden("list-descriptors") // meant only for bash completion
if registry.IsRemote() { validate.AddLatestFlag(topCommand, &topOptions.Latest)
_ = flags.MarkHidden("latest")
}
} }
func top(cmd *cobra.Command, args []string) error { func top(_ *cobra.Command, args []string) error {
if topOptions.ListDescriptors { if topOptions.ListDescriptors {
descriptors, err := util.GetContainerPidInformationDescriptors() descriptors, err := util.GetContainerPidInformationDescriptors()
if err != nil { if err != nil {

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/cmd/podman/validate"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -21,7 +21,7 @@ var (
Long: podUnpauseDescription, Long: podUnpauseDescription,
RunE: unpause, RunE: unpause,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
}, },
Example: `podman pod unpause podID1 podID2 Example: `podman pod unpause podID1 podID2
podman pod unpause --all podman pod unpause --all
@ -41,12 +41,10 @@ func init() {
}) })
flags := unpauseCommand.Flags() flags := unpauseCommand.Flags()
flags.BoolVarP(&unpauseOptions.All, "all", "a", false, "Pause all running pods") flags.BoolVarP(&unpauseOptions.All, "all", "a", false, "Pause all running pods")
flags.BoolVarP(&unpauseOptions.Latest, "latest", "l", false, "Act on the latest pod podman is aware of") validate.AddLatestFlag(unpauseCommand, &unpauseOptions.Latest)
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
} }
func unpause(cmd *cobra.Command, args []string) error {
func unpause(_ *cobra.Command, args []string) error {
var ( var (
errs utils.OutputErrors errs utils.OutputErrors
) )

View File

@ -5,7 +5,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
"sync" "sync"
"github.com/containers/common/pkg/config" "github.com/containers/common/pkg/config"
@ -45,7 +44,7 @@ func newPodmanConfig() {
case "linux": case "linux":
// Some linux clients might only be compiled without ABI // Some linux clients might only be compiled without ABI
// support (e.g., podman-remote). // support (e.g., podman-remote).
if abiSupport { if abiSupport && !remoteOverride {
mode = entities.ABIMode mode = entities.ABIMode
} else { } else {
mode = entities.TunnelMode mode = entities.TunnelMode
@ -55,19 +54,6 @@ func newPodmanConfig() {
os.Exit(1) os.Exit(1)
} }
// Check if need to fallback to the tunnel mode if --remote is used.
if abiSupport && mode == entities.ABIMode {
// cobra.Execute() may not be called yet, so we peek at os.Args.
for _, v := range os.Args {
// Prefix checking works because of how default EngineMode's
// have been defined.
if strings.HasPrefix(v, "--remote") {
mode = entities.TunnelMode
break
}
}
}
cfg, err := config.NewConfig("") cfg, err := config.NewConfig("")
if err != nil { if err != nil {
fmt.Fprint(os.Stderr, "Failed to obtain podman configuration: "+err.Error()) fmt.Fprint(os.Stderr, "Failed to obtain podman configuration: "+err.Error())

View File

@ -1,9 +1,26 @@
package registry package registry
import ( import (
"os"
"sync"
"github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/entities"
"github.com/spf13/cobra"
) )
var (
// Was --remote given on command line
remoteOverride bool
remoteSync sync.Once
)
// IsRemote returns true if podman was built to run remote
// Use in init() functions as a initialization check
func IsRemote() bool { func IsRemote() bool {
return podmanOptions.EngineMode == entities.TunnelMode remoteSync.Do(func() {
remote := &cobra.Command{}
remote.Flags().BoolVarP(&remoteOverride, "remote", "r", false, "")
_ = remote.ParseFlags(os.Args)
})
return podmanOptions.EngineMode == entities.TunnelMode || remoteOverride
} }

View File

@ -6,6 +6,7 @@ import (
"path" "path"
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
"strconv"
"strings" "strings"
"github.com/containers/common/pkg/config" "github.com/containers/common/pkg/config"
@ -20,7 +21,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag"
) )
// HelpTemplate is the help template for podman commands // HelpTemplate is the help template for podman commands
@ -79,7 +79,7 @@ func init() {
syslogHook, syslogHook,
) )
rootFlags(registry.PodmanConfig(), rootCmd.PersistentFlags()) rootFlags(rootCmd, registry.PodmanConfig())
// "version" is a local flag to avoid collisions with sub-commands that use "-v" // "version" is a local flag to avoid collisions with sub-commands that use "-v"
var dummyVersion bool var dummyVersion bool
@ -111,6 +111,15 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
cfg := registry.PodmanConfig() cfg := registry.PodmanConfig()
// Validate --remote and --latest not given on same command
latest := cmd.Flags().Lookup("latest")
if latest != nil {
value, _ := strconv.ParseBool(latest.Value.String())
if cfg.Remote && value {
return errors.Errorf("For %s \"--remote\" and \"--latest\", are mutually exclusive flags", cmd.CommandPath())
}
}
// Prep the engines // Prep the engines
if _, err := registry.NewImageEngine(cmd, args); err != nil { if _, err := registry.NewImageEngine(cmd, args); err != nil {
return err return err
@ -193,7 +202,7 @@ func loggingHook() {
} }
} }
if !found { if !found {
fmt.Fprintf(os.Stderr, "Log Level \"%s\" is not supported, choose from: %s\n", logLevel, strings.Join(logLevels, ", ")) fmt.Fprintf(os.Stderr, "Log Level %q is not supported, choose from: %s\n", logLevel, strings.Join(logLevels, ", "))
os.Exit(1) os.Exit(1)
} }
@ -209,44 +218,45 @@ func loggingHook() {
} }
} }
func rootFlags(opts *entities.PodmanConfig, flags *pflag.FlagSet) { func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
// V2 flags cfg := opts.Config
flags.BoolVarP(&opts.Remote, "remote", "r", false, "Access remote Podman service (default false)")
lFlags := cmd.Flags()
custom, _ := config.ReadCustomConfig() custom, _ := config.ReadCustomConfig()
defaultURI := custom.Engine.RemoteURI defaultURI := custom.Engine.RemoteURI
if defaultURI == "" { if defaultURI == "" {
defaultURI = registry.DefaultAPIAddress() defaultURI = registry.DefaultAPIAddress()
} }
flags.StringVar(&opts.URI, "url", defaultURI, "URL to access Podman service (CONTAINER_HOST)") lFlags.BoolVarP(&opts.Remote, "remote", "r", false, "Access remote Podman service (default false)")
flags.StringVar(&opts.Identity, "identity", custom.Engine.RemoteIdentity, "path to SSH identity file, (CONTAINER_SSHKEY)") lFlags.StringVar(&opts.URI, "url", defaultURI, "URL to access Podman service (CONTAINER_HOST)")
lFlags.StringVar(&opts.Identity, "identity", custom.Engine.RemoteIdentity, "path to SSH identity file, (CONTAINER_SSHKEY)")
cfg := opts.Config pFlags := cmd.PersistentFlags()
flags.StringVar(&cfg.Engine.CgroupManager, "cgroup-manager", cfg.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")") pFlags.StringVar(&cfg.Engine.CgroupManager, "cgroup-manager", cfg.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")")
flags.StringVar(&opts.CPUProfile, "cpu-profile", "", "Path for the cpu profiling results") pFlags.StringVar(&opts.CPUProfile, "cpu-profile", "", "Path for the cpu profiling results")
flags.StringVar(&opts.ConmonPath, "conmon", "", "Path of the conmon binary") pFlags.StringVar(&opts.ConmonPath, "conmon", "", "Path of the conmon binary")
flags.StringVar(&cfg.Engine.NetworkCmdPath, "network-cmd-path", cfg.Engine.NetworkCmdPath, "Path to the command for configuring the network") pFlags.StringVar(&cfg.Engine.NetworkCmdPath, "network-cmd-path", cfg.Engine.NetworkCmdPath, "Path to the command for configuring the network")
flags.StringVar(&cfg.Network.NetworkConfigDir, "cni-config-dir", cfg.Network.NetworkConfigDir, "Path of the configuration directory for CNI networks") pFlags.StringVar(&cfg.Network.NetworkConfigDir, "cni-config-dir", cfg.Network.NetworkConfigDir, "Path of the configuration directory for CNI networks")
flags.StringVar(&cfg.Containers.DefaultMountsFile, "default-mounts-file", cfg.Containers.DefaultMountsFile, "Path to default mounts file") pFlags.StringVar(&cfg.Containers.DefaultMountsFile, "default-mounts-file", cfg.Containers.DefaultMountsFile, "Path to default mounts file")
flags.StringVar(&cfg.Engine.EventsLogger, "events-backend", cfg.Engine.EventsLogger, `Events backend to use ("file"|"journald"|"none")`) pFlags.StringVar(&cfg.Engine.EventsLogger, "events-backend", cfg.Engine.EventsLogger, `Events backend to use ("file"|"journald"|"none")`)
flags.StringSliceVar(&cfg.Engine.HooksDir, "hooks-dir", cfg.Engine.HooksDir, "Set the OCI hooks directory path (may be set multiple times)") pFlags.StringSliceVar(&cfg.Engine.HooksDir, "hooks-dir", cfg.Engine.HooksDir, "Set the OCI hooks directory path (may be set multiple times)")
flags.IntVar(&opts.MaxWorks, "max-workers", (runtime.NumCPU()*3)+1, "The maximum number of workers for parallel operations") pFlags.IntVar(&opts.MaxWorks, "max-workers", (runtime.NumCPU()*3)+1, "The maximum number of workers for parallel operations")
flags.StringVar(&cfg.Engine.Namespace, "namespace", cfg.Engine.Namespace, "Set the libpod namespace, used to create separate views of the containers and pods on the system") pFlags.StringVar(&cfg.Engine.Namespace, "namespace", cfg.Engine.Namespace, "Set the libpod namespace, used to create separate views of the containers and pods on the system")
flags.StringVar(&cfg.Engine.StaticDir, "root", "", "Path to the root directory in which data, including images, is stored") pFlags.StringVar(&cfg.Engine.StaticDir, "root", "", "Path to the root directory in which data, including images, is stored")
flags.StringVar(&opts.RegistriesConf, "registries-conf", "", "Path to a registries.conf to use for image processing") pFlags.StringVar(&opts.RegistriesConf, "registries-conf", "", "Path to a registries.conf to use for image processing")
flags.StringVar(&opts.Runroot, "runroot", "", "Path to the 'run directory' where all state information is stored") pFlags.StringVar(&opts.Runroot, "runroot", "", "Path to the 'run directory' where all state information is stored")
flags.StringVar(&opts.RuntimePath, "runtime", "", "Path to the OCI-compatible binary used to run containers, default is /usr/bin/runc") pFlags.StringVar(&opts.RuntimePath, "runtime", "", "Path to the OCI-compatible binary used to run containers, default is /usr/bin/runc")
// -s is deprecated due to conflict with -s on subcommands // -s is deprecated due to conflict with -s on subcommands
flags.StringVar(&opts.StorageDriver, "storage-driver", "", "Select which storage driver is used to manage storage of images and containers (default is overlay)") pFlags.StringVar(&opts.StorageDriver, "storage-driver", "", "Select which storage driver is used to manage storage of images and containers (default is overlay)")
flags.StringArrayVar(&opts.StorageOpts, "storage-opt", []string{}, "Used to pass an option to the storage driver") pFlags.StringArrayVar(&opts.StorageOpts, "storage-opt", []string{}, "Used to pass an option to the storage driver")
flags.StringVar(&opts.Engine.TmpDir, "tmpdir", "", "Path to the tmp directory for libpod state content.\n\nNote: use the environment variable 'TMPDIR' to change the temporary storage location for container images, '/var/tmp'.\n") pFlags.StringVar(&opts.Engine.TmpDir, "tmpdir", "", "Path to the tmp directory for libpod state content.\n\nNote: use the environment variable 'TMPDIR' to change the temporary storage location for container images, '/var/tmp'.\n")
flags.BoolVar(&opts.Trace, "trace", false, "Enable opentracing output (default false)") pFlags.BoolVar(&opts.Trace, "trace", false, "Enable opentracing output (default false)")
// Override default --help information of `--help` global flag // Override default --help information of `--help` global flag
var dummyHelp bool var dummyHelp bool
flags.BoolVar(&dummyHelp, "help", false, "Help for podman") pFlags.BoolVar(&dummyHelp, "help", false, "Help for podman")
flags.StringVar(&logLevel, "log-level", logLevel, fmt.Sprintf("Log messages above specified level (%s)", strings.Join(logLevels, ", "))) pFlags.StringVar(&logLevel, "log-level", logLevel, fmt.Sprintf("Log messages above specified level (%s)", strings.Join(logLevels, ", ")))
// Hide these flags for both ABI and Tunneling // Hide these flags for both ABI and Tunneling
for _, f := range []string{ for _, f := range []string{
@ -256,13 +266,13 @@ func rootFlags(opts *entities.PodmanConfig, flags *pflag.FlagSet) {
"registries-conf", "registries-conf",
"trace", "trace",
} { } {
if err := flags.MarkHidden(f); err != nil { if err := pFlags.MarkHidden(f); err != nil {
logrus.Warnf("unable to mark %s flag as hidden: %s", f, err.Error()) logrus.Warnf("unable to mark %s flag as hidden: %s", f, err.Error())
} }
} }
// Only create these flags for ABI connections // Only create these flags for ABI connections
if !registry.IsRemote() { if !registry.IsRemote() {
flags.BoolVar(&useSyslog, "syslog", false, "Output logging information to syslog as well as the console (default false)") pFlags.BoolVar(&useSyslog, "syslog", false, "Output logging information to syslog as well as the console (default false)")
} }
} }

View File

@ -60,7 +60,6 @@ func init() {
}) })
flags := connectionCmd.Flags() flags := connectionCmd.Flags()
flags.StringVar(&cOpts.Identity, "identity", "", "path to ssh identity file")
flags.IntVarP(&cOpts.Port, "port", "p", 22, "port number for destination") flags.IntVarP(&cOpts.Port, "port", "p", 22, "port number for destination")
flags.StringVar(&cOpts.UDSPath, "socket-path", "", "path to podman socket on remote host. (default '/run/podman/podman.sock' or '/run/user/{uid}/podman/podman.sock)") flags.StringVar(&cOpts.UDSPath, "socket-path", "", "path to podman socket on remote host. (default '/run/podman/podman.sock' or '/run/user/{uid}/podman/podman.sock)")
} }

View File

@ -13,11 +13,10 @@ var (
// Command: podman _system_ // Command: podman _system_
systemCmd = &cobra.Command{ systemCmd = &cobra.Command{
Use: "system", Use: "system",
Short: "Manage podman", Short: "Manage podman",
Long: "Manage podman", Long: "Manage podman",
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
} }
) )

View File

@ -2,6 +2,7 @@ package validate
import ( import (
"fmt" "fmt"
"strconv"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -28,8 +29,119 @@ func IDOrLatestArgs(cmd *cobra.Command, args []string) error {
if len(args) > 1 { if len(args) > 1 {
return fmt.Errorf("`%s` accepts at most one argument", cmd.CommandPath()) return fmt.Errorf("`%s` accepts at most one argument", cmd.CommandPath())
} }
if len(args) == 0 && !cmd.Flag("latest").Changed {
return fmt.Errorf("`%s` requires a name, id, or the \"--latest\" flag", cmd.CommandPath()) latest := cmd.Flag("latest")
if latest != nil {
given, _ := strconv.ParseBool(cmd.Flag("latest").Value.String())
if len(args) == 0 && !given {
return fmt.Errorf("%q requires a name, id, or the \"--latest\" flag", cmd.CommandPath())
}
}
return nil
}
// TODO: the two functions CheckAllLatestAndCIDFile and CheckAllLatestAndPodIDFile are almost identical.
// It may be worth looking into generalizing the two a bit more and share code but time is scarce and
// we only live once.
// CheckAllLatestAndCIDFile checks that --all and --latest are used correctly.
// If cidfile is set, also check for the --cidfile flag.
func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool, cidfile bool) error {
argLen := len(args)
if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
if !cidfile {
return errors.New("unable to lookup values for 'latest' or 'all'")
} else if c.Flags().Lookup("cidfile") == nil {
return errors.New("unable to lookup values for 'latest', 'all' or 'cidfile'")
}
}
specifiedAll, _ := c.Flags().GetBool("all")
specifiedLatest, _ := c.Flags().GetBool("latest")
specifiedCIDFile := false
if cid, _ := c.Flags().GetStringArray("cidfile"); len(cid) > 0 {
specifiedCIDFile = true
}
if specifiedCIDFile && (specifiedAll || specifiedLatest) {
return errors.Errorf("--all, --latest and --cidfile cannot be used together")
} else if specifiedAll && specifiedLatest {
return errors.Errorf("--all and --latest cannot be used together")
}
if (argLen > 0) && specifiedAll {
return errors.Errorf("no arguments are needed with --all")
}
if ignoreArgLen {
return nil
}
if argLen > 0 {
if specifiedLatest {
return errors.Errorf("no arguments are needed with --latest")
} else if cidfile && (specifiedLatest || specifiedCIDFile) {
return errors.Errorf("no arguments are needed with --latest or --cidfile")
}
}
if specifiedCIDFile {
return nil
}
if argLen < 1 && !specifiedAll && !specifiedLatest && !specifiedCIDFile {
return errors.Errorf("you must provide at least one name or id")
}
return nil
}
// CheckAllLatestAndPodIDFile checks that --all and --latest are used correctly.
// If withIDFile is set, also check for the --pod-id-file flag.
func CheckAllLatestAndPodIDFile(c *cobra.Command, args []string, ignoreArgLen bool, withIDFile bool) error {
argLen := len(args)
if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
if !withIDFile {
return errors.New("unable to lookup values for 'latest' or 'all'")
} else if c.Flags().Lookup("pod-id-file") == nil {
return errors.New("unable to lookup values for 'latest', 'all' or 'pod-id-file'")
}
}
specifiedAll, _ := c.Flags().GetBool("all")
specifiedLatest, _ := c.Flags().GetBool("latest")
specifiedPodIDFile := false
if pid, _ := c.Flags().GetStringArray("pod-id-file"); len(pid) > 0 {
specifiedPodIDFile = true
}
if specifiedPodIDFile && (specifiedAll || specifiedLatest) {
return errors.Errorf("--all, --latest and --pod-id-file cannot be used together")
} else if specifiedAll && specifiedLatest {
return errors.Errorf("--all and --latest cannot be used together")
}
if (argLen > 0) && specifiedAll {
return errors.Errorf("no arguments are needed with --all")
}
if ignoreArgLen {
return nil
}
if argLen > 0 {
if specifiedLatest {
return errors.Errorf("no arguments are needed with --latest")
} else if withIDFile && (specifiedLatest || specifiedPodIDFile) {
return errors.Errorf("no arguments are needed with --latest or --pod-id-file")
}
}
if specifiedPodIDFile {
return nil
}
if argLen < 1 && !specifiedAll && !specifiedLatest && !specifiedPodIDFile {
return errors.Errorf("you must provide at least one name or id")
} }
return nil return nil
} }

View File

@ -0,0 +1,15 @@
package validate
import (
"github.com/containers/libpod/cmd/podman/registry"
"github.com/spf13/cobra"
)
func AddLatestFlag(cmd *cobra.Command, b *bool) {
// Initialization flag verification
cmd.Flags().BoolVarP(b, "latest", "l", false,
"Act on the latest container podman is aware of\nNot supported with the \"--remote\" flag")
if registry.IsRemote() {
_ = cmd.Flags().MarkHidden("latest")
}
}

View File

@ -13,11 +13,10 @@ var (
// Command: podman _volume_ // Command: podman _volume_
volumeCmd = &cobra.Command{ volumeCmd = &cobra.Command{
Use: "volume", Use: "volume",
Short: "Manage volumes", Short: "Manage volumes",
Long: "Volumes are created in and can be shared between containers", Long: "Volumes are created in and can be shared between containers",
TraverseChildren: true, RunE: validate.SubCommandExists,
RunE: validate.SubCommandExists,
} }
) )