mirror of
https://github.com/containers/podman.git
synced 2025-06-29 06:57:13 +08:00
@ -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/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -17,12 +18,7 @@ var (
|
|||||||
Short: "Attach to a running container",
|
Short: "Attach to a running container",
|
||||||
Long: attachDescription,
|
Long: attachDescription,
|
||||||
RunE: attach,
|
RunE: attach,
|
||||||
Args: func(cmd *cobra.Command, args []string) error {
|
Args: validate.IdOrLatestArgs,
|
||||||
if len(args) > 1 || (len(args) == 0 && !cmd.Flag("latest").Changed) {
|
|
||||||
return errors.Errorf("attach requires the name or id of one running container or the latest flag")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
Example: `podman attach ctrID
|
Example: `podman attach ctrID
|
||||||
podman attach 1234
|
podman attach 1234
|
||||||
podman attach --no-stdin foobar`,
|
podman attach --no-stdin foobar`,
|
||||||
@ -33,6 +29,7 @@ var (
|
|||||||
Short: attachCommand.Short,
|
Short: attachCommand.Short,
|
||||||
Long: attachCommand.Long,
|
Long: attachCommand.Long,
|
||||||
RunE: attachCommand.RunE,
|
RunE: attachCommand.RunE,
|
||||||
|
Args: validate.IdOrLatestArgs,
|
||||||
Example: `podman container attach ctrID
|
Example: `podman container attach ctrID
|
||||||
podman container attach 1234
|
podman container attach 1234
|
||||||
podman container attach --no-stdin foobar`,
|
podman container attach --no-stdin foobar`,
|
||||||
|
@ -30,6 +30,7 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerCommitCommand = &cobra.Command{
|
containerCommitCommand = &cobra.Command{
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
Use: commitCommand.Use,
|
Use: commitCommand.Use,
|
||||||
Short: commitCommand.Short,
|
Short: commitCommand.Short,
|
||||||
Long: commitCommand.Long,
|
Long: commitCommand.Long,
|
||||||
|
@ -33,6 +33,7 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerCreateCommand = &cobra.Command{
|
containerCreateCommand = &cobra.Command{
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
Use: createCommand.Use,
|
Use: createCommand.Use,
|
||||||
Short: createCommand.Short,
|
Short: createCommand.Short,
|
||||||
Long: createCommand.Long,
|
Long: createCommand.Long,
|
||||||
|
@ -20,6 +20,7 @@ var (
|
|||||||
Short: "Run a process in a running container",
|
Short: "Run a process in a running container",
|
||||||
Long: execDescription,
|
Long: execDescription,
|
||||||
RunE: exec,
|
RunE: exec,
|
||||||
|
DisableFlagsInUseLine: true,
|
||||||
Example: `podman exec -it ctrID ls
|
Example: `podman exec -it ctrID ls
|
||||||
podman exec -it -w /tmp myCtr pwd
|
podman exec -it -w /tmp myCtr pwd
|
||||||
podman exec --user root ctrID ls`,
|
podman exec --user root ctrID ls`,
|
||||||
@ -30,6 +31,7 @@ var (
|
|||||||
Short: execCommand.Short,
|
Short: execCommand.Short,
|
||||||
Long: execCommand.Long,
|
Long: execCommand.Long,
|
||||||
RunE: execCommand.RunE,
|
RunE: execCommand.RunE,
|
||||||
|
DisableFlagsInUseLine: true,
|
||||||
Example: `podman container exec -it ctrID ls
|
Example: `podman container exec -it ctrID ls
|
||||||
podman container exec -it -w /tmp myCtr pwd
|
podman container exec -it -w /tmp myCtr pwd
|
||||||
podman container exec --user root ctrID ls`,
|
podman container exec --user root ctrID ls`,
|
||||||
@ -79,6 +81,10 @@ func init() {
|
|||||||
|
|
||||||
func exec(cmd *cobra.Command, args []string) error {
|
func exec(cmd *cobra.Command, args []string) error {
|
||||||
var nameOrId string
|
var nameOrId string
|
||||||
|
|
||||||
|
if len(args) == 0 && !execOpts.Latest {
|
||||||
|
return errors.New("exec requires the name or ID of a container or the --latest flag")
|
||||||
|
}
|
||||||
execOpts.Cmd = args
|
execOpts.Cmd = args
|
||||||
if !execOpts.Latest {
|
if !execOpts.Latest {
|
||||||
execOpts.Cmd = args[1:]
|
execOpts.Cmd = args[1:]
|
||||||
|
@ -28,6 +28,7 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerExportCommand = &cobra.Command{
|
containerExportCommand = &cobra.Command{
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
Use: exportCommand.Use,
|
Use: exportCommand.Use,
|
||||||
Short: exportCommand.Short,
|
Short: exportCommand.Short,
|
||||||
Long: exportCommand.Long,
|
Long: exportCommand.Long,
|
||||||
|
@ -30,6 +30,9 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerKillCommand = &cobra.Command{
|
containerKillCommand = &cobra.Command{
|
||||||
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
|
||||||
|
},
|
||||||
Use: killCommand.Use,
|
Use: killCommand.Use,
|
||||||
Short: killCommand.Short,
|
Short: killCommand.Short,
|
||||||
Long: killCommand.Long,
|
Long: killCommand.Long,
|
||||||
|
@ -38,6 +38,9 @@ var (
|
|||||||
Short: rmCommand.Use,
|
Short: rmCommand.Use,
|
||||||
Long: rmCommand.Long,
|
Long: rmCommand.Long,
|
||||||
RunE: rmCommand.RunE,
|
RunE: rmCommand.RunE,
|
||||||
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return parse.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
|
||||||
podman container rm --force --all
|
podman container rm --force --all
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
runDescription = "Runs a command in a new container from the given image"
|
runDescription = "Runs a command in a new container from the given image"
|
||||||
runCommand = &cobra.Command{
|
runCommand = &cobra.Command{
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
Use: "run [flags] IMAGE [COMMAND [ARG...]]",
|
Use: "run [flags] IMAGE [COMMAND [ARG...]]",
|
||||||
Short: "Run a command in a new container",
|
Short: "Run a command in a new container",
|
||||||
Long: runDescription,
|
Long: runDescription,
|
||||||
@ -30,6 +31,7 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerRunCommand = &cobra.Command{
|
containerRunCommand = &cobra.Command{
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
Use: runCommand.Use,
|
Use: runCommand.Use,
|
||||||
Short: runCommand.Short,
|
Short: runCommand.Short,
|
||||||
Long: runCommand.Long,
|
Long: runCommand.Long,
|
||||||
|
@ -34,6 +34,9 @@ var (
|
|||||||
Short: stopCommand.Short,
|
Short: stopCommand.Short,
|
||||||
Long: stopCommand.Long,
|
Long: stopCommand.Long,
|
||||||
RunE: stopCommand.RunE,
|
RunE: stopCommand.RunE,
|
||||||
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return parse.CheckAllLatestAndCIDFile(cmd, args, false, true)
|
||||||
|
},
|
||||||
Example: `podman container stop ctrID
|
Example: `podman container stop ctrID
|
||||||
podman container stop --latest
|
podman container stop --latest
|
||||||
podman container stop --time 2 mywebserver 6e534f14da9d`,
|
podman container stop --time 2 mywebserver 6e534f14da9d`,
|
||||||
|
@ -40,6 +40,9 @@ var (
|
|||||||
Short: umountCommand.Short,
|
Short: umountCommand.Short,
|
||||||
Long: umountCommand.Long,
|
Long: umountCommand.Long,
|
||||||
RunE: umountCommand.RunE,
|
RunE: umountCommand.RunE,
|
||||||
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return parse.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
|
||||||
podman container umount --all`,
|
podman container umount --all`,
|
||||||
|
@ -34,6 +34,7 @@ var (
|
|||||||
Short: waitCommand.Short,
|
Short: waitCommand.Short,
|
||||||
Long: waitCommand.Long,
|
Long: waitCommand.Long,
|
||||||
RunE: waitCommand.RunE,
|
RunE: waitCommand.RunE,
|
||||||
|
Args: validate.IdOrLatestArgs,
|
||||||
Example: `podman container wait --latest
|
Example: `podman container wait --latest
|
||||||
podman container wait --interval 5000 ctrID
|
podman container wait --interval 5000 ctrID
|
||||||
podman container wait ctrID1 ctrID2`,
|
podman container wait ctrID1 ctrID2`,
|
||||||
|
@ -45,6 +45,7 @@ var (
|
|||||||
Short: pullCmd.Short,
|
Short: pullCmd.Short,
|
||||||
Long: pullCmd.Long,
|
Long: pullCmd.Long,
|
||||||
RunE: pullCmd.RunE,
|
RunE: pullCmd.RunE,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
Example: `podman image pull imageName
|
Example: `podman image pull imageName
|
||||||
podman image pull fedora:latest`,
|
podman image pull fedora:latest`,
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ type loginOptionsWrapper struct {
|
|||||||
var (
|
var (
|
||||||
loginOptions = loginOptionsWrapper{}
|
loginOptions = loginOptionsWrapper{}
|
||||||
loginCommand = &cobra.Command{
|
loginCommand = &cobra.Command{
|
||||||
Use: "login [flags] REGISTRY",
|
Use: "login [flags] [REGISTRY]",
|
||||||
Short: "Login to a container registry",
|
Short: "Login to a container registry",
|
||||||
Long: "Login to a container registry on a specified server.",
|
Long: "Login to a container registry on a specified server.",
|
||||||
RunE: login,
|
RunE: login,
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
logoutOptions = auth.LogoutOptions{}
|
logoutOptions = auth.LogoutOptions{}
|
||||||
logoutCommand = &cobra.Command{
|
logoutCommand = &cobra.Command{
|
||||||
Use: "logout [flags] REGISTRY",
|
Use: "logout [flags] [REGISTRY]",
|
||||||
Short: "Logout of a container registry",
|
Short: "Logout of a container registry",
|
||||||
Long: "Remove the cached username and password for the registry.",
|
Long: "Remove the cached username and password for the registry.",
|
||||||
RunE: logout,
|
RunE: logout,
|
||||||
|
@ -55,11 +55,24 @@ function check_help() {
|
|||||||
|
|
||||||
# If usage has required arguments, try running without them
|
# If usage has required arguments, try running without them
|
||||||
if expr "$usage" : '.*\[flags\] [A-Z]' >/dev/null; then
|
if expr "$usage" : '.*\[flags\] [A-Z]' >/dev/null; then
|
||||||
if [ "$cmd" != "stats"]; then
|
# Exceptions: these commands don't work rootless
|
||||||
dprint "podman $@ $cmd (without required args)"
|
if is_rootless; then
|
||||||
run_podman 125 "$@" $cmd
|
# "pause is not supported for rootless containers"
|
||||||
is "$output" "Error:"
|
if [ "$cmd" = "pause" -o "$cmd" = "unpause" ]; then
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
# "network rm" too
|
||||||
|
if [ "$@" = "network" -a "$cmd" = "rm" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The </dev/null protects us from 'podman login' which will
|
||||||
|
# try to read username/password from stdin.
|
||||||
|
dprint "podman $@ $cmd (without required args)"
|
||||||
|
run_podman 125 "$@" $cmd </dev/null
|
||||||
|
is "$output" "Error:.* \(require\|specif\|must\|provide\|need\|choose\|accepts\)" \
|
||||||
|
"'podman $@ $cmd' without required arg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
count=$(expr $count + 1)
|
count=$(expr $count + 1)
|
||||||
|
Reference in New Issue
Block a user