diff options
Diffstat (limited to 'cmd/podman/common.go')
-rw-r--r-- | cmd/podman/common.go | 834 |
1 files changed, 404 insertions, 430 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go index 82d60d62e..e297f3921 100644 --- a/cmd/podman/common.go +++ b/cmd/podman/common.go @@ -3,35 +3,21 @@ package main import ( "context" "fmt" + "github.com/spf13/cobra" "os" - "reflect" - "regexp" - "sort" "strings" "github.com/containers/buildah" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/rootless" "github.com/containers/storage" "github.com/fatih/camelcase" "github.com/pkg/errors" - "github.com/urfave/cli" ) var ( - stores = make(map[storage.Store]struct{}) - LatestFlag = cli.BoolFlag{ - Name: "latest, l", - Usage: "Act on the latest container podman is aware of", - } - LatestPodFlag = cli.BoolFlag{ - Name: "latest, l", - Usage: "Act on the latest pod podman is aware of", - } - WorkDirFlag = cli.StringFlag{ - Name: "workdir, w", - Usage: "Working directory inside the container", - } + stores = make(map[storage.Store]struct{}) ) const ( @@ -50,61 +36,25 @@ func shortID(id string) string { return id } -func usageErrorHandler(context *cli.Context, err error, _ bool) error { - cmd := context.App.Name - if len(context.Command.Name) > 0 { - cmd = cmd + " " + context.Command.Name - } - return fmt.Errorf("%s\nSee '%s --help'.", err, cmd) -} - -func commandNotFoundHandler(context *cli.Context, command string) { - fmt.Fprintf(os.Stderr, "Command %q not found.\nSee `%s --help`.\n", command, context.App.Name) - os.Exit(exitCode) -} - -// validateFlags searches for StringFlags or StringSlice flags that never had -// a value set. This commonly occurs when the CLI mistakenly takes the next -// option and uses it as a value. -func validateFlags(c *cli.Context, flags []cli.Flag) error { - for _, flag := range flags { - switch reflect.TypeOf(flag).String() { - case "cli.StringSliceFlag": - { - f := flag.(cli.StringSliceFlag) - name := strings.Split(f.Name, ",") - val := c.StringSlice(name[0]) - for _, v := range val { - if ok, _ := regexp.MatchString("^-.+", v); ok { - return errors.Errorf("option --%s requires a value", name[0]) - } - } - } - case "cli.StringFlag": - { - f := flag.(cli.StringFlag) - name := strings.Split(f.Name, ",") - val := c.String(name[0]) - if ok, _ := regexp.MatchString("^-.+", val); ok { - return errors.Errorf("option --%s requires a value", name[0]) - } - } - } - } - return nil -} - // checkAllAndLatest checks that --all and --latest are used correctly -func checkAllAndLatest(c *cli.Context) error { - argLen := len(c.Args()) - if (c.Bool("all") || c.Bool("latest")) && argLen > 0 { - return errors.Errorf("no arguments are needed with --all or --latest") +func checkAllAndLatest(c *cobra.Command, args []string, ignoreArgLen bool) error { + argLen := len(args) + if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil { + return errors.New("unable to lookup values for 'latest' or 'all'") } - if c.Bool("all") && c.Bool("latest") { + all, _ := c.Flags().GetBool("all") + latest, _ := c.Flags().GetBool("latest") + if all && latest { return errors.Errorf("--all and --latest cannot be used together") } - if argLen < 1 && !c.Bool("all") && !c.Bool("latest") { - return errors.Errorf("you must provide at least one pod name or id") + if ignoreArgLen { + return nil + } + if (all || latest) && argLen > 0 { + return errors.Errorf("no arguments are needed with --all or --latest") + } + if argLen < 1 && !all && !latest { + return errors.Errorf("you must provide at least one name or id") } return nil } @@ -117,7 +67,7 @@ func checkAllAndLatest(c *cli.Context) error { // is desired a -1 can be used to get all containers. For a better // error message, if the filter fails, a corresponding verb can be // specified which will then appear in the error message. -func getAllOrLatestContainers(c *cli.Context, runtime *libpod.Runtime, filterState libpod.ContainerStatus, verb string) ([]*libpod.Container, error) { +func getAllOrLatestContainers(c *cliconfig.PodmanCommand, runtime *libpod.Runtime, filterState libpod.ContainerStatus, verb string) ([]*libpod.Container, error) { var containers []*libpod.Container var lastError error var err error @@ -142,7 +92,7 @@ func getAllOrLatestContainers(c *cli.Context, runtime *libpod.Runtime, filterSta } containers = append(containers, lastCtr) } else { - args := c.Args() + args := c.InputArgs for _, i := range args { container, err := runtime.LookupContainer(i) if err != nil { @@ -163,6 +113,9 @@ func getAllOrLatestContainers(c *cli.Context, runtime *libpod.Runtime, filterSta // getContext returns a non-nil, empty context func getContext() context.Context { + if Ctx != nil { + return Ctx + } return context.TODO() } @@ -173,363 +126,367 @@ func getDefaultNetwork() string { return "bridge" } -// Common flags shared between commands -var createFlags = []cli.Flag{ - cli.StringSliceFlag{ - Name: "add-host", - Usage: "Add a custom host-to-IP mapping (host:ip) (default [])", - }, - cli.StringSliceFlag{ - Name: "annotation", - Usage: "Add annotations to container (key:value) (default [])", - }, - cli.StringSliceFlag{ - Name: "attach, a", - Usage: "Attach to STDIN, STDOUT or STDERR (default [])", - }, - cli.StringFlag{ - Name: "blkio-weight", - Usage: "Block IO weight (relative weight) accepts a weight value between 10 and 1000.", - }, - cli.StringSliceFlag{ - Name: "blkio-weight-device", - Usage: "Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`)", - }, - cli.StringSliceFlag{ - Name: "cap-add", - Usage: "Add capabilities to the container", - }, - cli.StringSliceFlag{ - Name: "cap-drop", - Usage: "Drop capabilities from the container", - }, - cli.StringFlag{ - Name: "cgroup-parent", - Usage: "Optional parent cgroup for the container", - }, - cli.StringFlag{ - Name: "cidfile", - Usage: "Write the container ID to the file", - }, - cli.StringFlag{ - Name: "conmon-pidfile", - Usage: "Path to the file that will receive the PID of conmon", - }, - cli.Uint64Flag{ - Name: "cpu-period", - Usage: "Limit the CPU CFS (Completely Fair Scheduler) period", - }, - cli.Int64Flag{ - Name: "cpu-quota", - Usage: "Limit the CPU CFS (Completely Fair Scheduler) quota", - }, - cli.Uint64Flag{ - Name: "cpu-rt-period", - Usage: "Limit the CPU real-time period in microseconds", - }, - cli.Int64Flag{ - Name: "cpu-rt-runtime", - Usage: "Limit the CPU real-time runtime in microseconds", - }, - cli.Uint64Flag{ - Name: "cpu-shares", - Usage: "CPU shares (relative weight)", - }, - cli.Float64Flag{ - Name: "cpus", - Usage: "Number of CPUs. The default is 0.000 which means no limit", - }, - cli.StringFlag{ - Name: "cpuset-cpus", - Usage: "CPUs in which to allow execution (0-3, 0,1)", - }, - cli.StringFlag{ - Name: "cpuset-mems", - Usage: "Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.", - }, - cli.BoolFlag{ - Name: "detach, d", - Usage: "Run container in background and print container ID", - }, - cli.StringFlag{ - Name: "detach-keys", - Usage: "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`", - }, - cli.StringSliceFlag{ - Name: "device", - Usage: "Add a host device to the container (default [])", - }, - cli.StringSliceFlag{ - Name: "device-read-bps", - Usage: "Limit read rate (bytes per second) from a device (e.g. --device-read-bps=/dev/sda:1mb)", - }, - cli.StringSliceFlag{ - Name: "device-read-iops", - Usage: "Limit read rate (IO per second) from a device (e.g. --device-read-iops=/dev/sda:1000)", - }, - cli.StringSliceFlag{ - Name: "device-write-bps", - Usage: "Limit write rate (bytes per second) to a device (e.g. --device-write-bps=/dev/sda:1mb)", - }, - cli.StringSliceFlag{ - Name: "device-write-iops", - Usage: "Limit write rate (IO per second) to a device (e.g. --device-write-iops=/dev/sda:1000)", - }, - cli.StringSliceFlag{ - Name: "dns", - Usage: "Set custom DNS servers", - }, - cli.StringSliceFlag{ - Name: "dns-opt", - Usage: "Set custom DNS options", - }, - cli.StringSliceFlag{ - Name: "dns-search", - Usage: "Set custom DNS search domains", - }, - cli.StringFlag{ - Name: "entrypoint", - Usage: "Overwrite the default ENTRYPOINT of the image", - }, - cli.StringSliceFlag{ - Name: "env, e", - Usage: "Set environment variables in container", - }, - cli.StringSliceFlag{ - Name: "env-file", - Usage: "Read in a file of environment variables", - }, - cli.StringSliceFlag{ - Name: "expose", - Usage: "Expose a port or a range of ports (default [])", - }, - cli.StringSliceFlag{ - Name: "gidmap", - Usage: "GID map to use for the user namespace", - }, - cli.StringSliceFlag{ - Name: "group-add", - Usage: "Add additional groups to join (default [])", - }, - cli.BoolFlag{ - Name: "help", - Hidden: true, - }, - cli.StringFlag{ - Name: "hostname, h", - Usage: "Set container hostname", - }, - cli.StringFlag{ - Name: "image-volume, builtin-volume", - Usage: "Tells podman how to handle the builtin image volumes. The options are: 'bind', 'tmpfs', or 'ignore' (default 'bind')", - Value: "bind", - }, - cli.BoolFlag{ - Name: "init", - Usage: "Run an init binary inside the container that forwards signals and reaps processes", - }, - cli.StringFlag{ - Name: "init-path", +func getCreateFlags(c *cliconfig.PodmanCommand) { + + createFlags := c.Flags() + + createFlags.StringSlice( + "add-host", []string{}, + "Add a custom host-to-IP mapping (host:ip) (default [])", + ) + createFlags.StringSlice( + "annotation", []string{}, + "Add annotations to container (key:value) (default [])", + ) + createFlags.StringSliceP( + "attach", "a", []string{}, + "Attach to STDIN, STDOUT or STDERR (default [])", + ) + createFlags.String( + "blkio-weight", "", + "Block IO weight (relative weight) accepts a weight value between 10 and 1000.", + ) + createFlags.StringSlice( + "blkio-weight-device", []string{}, + "Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`)", + ) + createFlags.StringSlice( + "cap-add", []string{}, + "Add capabilities to the container", + ) + createFlags.StringSlice( + "cap-drop", []string{}, + "Drop capabilities from the container", + ) + createFlags.String( + "cgroup-parent", "", + "Optional parent cgroup for the container", + ) + createFlags.String( + "cidfile", "", + "Write the container ID to the file", + ) + createFlags.String( + "conmon-pidfile", "", + "Path to the file that will receive the PID of conmon", + ) + createFlags.Uint64( + "cpu-period", 0, + "Limit the CPU CFS (Completely Fair Scheduler) period", + ) + createFlags.Int64( + "cpu-quota", 0, + "Limit the CPU CFS (Completely Fair Scheduler) quota", + ) + createFlags.Uint64( + "cpu-rt-period", 0, + "Limit the CPU real-time period in microseconds", + ) + createFlags.Int64( + "cpu-rt-runtime", 0, + "Limit the CPU real-time runtime in microseconds", + ) + createFlags.Uint64( + "cpu-shares", 0, + "CPU shares (relative weight)", + ) + createFlags.Float64( + "cpus", 0, + "Number of CPUs. The default is 0.000 which means no limit", + ) + createFlags.String( + "cpuset-cpus", "", + "CPUs in which to allow execution (0-3, 0,1)", + ) + createFlags.String( + "cpuset-mems", "", + "Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.", + ) + createFlags.BoolP( + "detach", "d", false, + "Run container in background and print container ID", + ) + createFlags.String( + "detach-keys", "", + "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`", + ) + createFlags.StringSlice( + "device", []string{}, + "Add a host device to the container (default [])", + ) + createFlags.StringSlice( + "device-read-bps", []string{}, + "Limit read rate (bytes per second) from a device (e.g. --device-read-bps=/dev/sda:1mb)", + ) + createFlags.StringSlice( + "device-read-iops", []string{}, + "Limit read rate (IO per second) from a device (e.g. --device-read-iops=/dev/sda:1000)", + ) + createFlags.StringSlice( + "device-write-bps", []string{}, + "Limit write rate (bytes per second) to a device (e.g. --device-write-bps=/dev/sda:1mb)", + ) + createFlags.StringSlice( + "device-write-iops", []string{}, + "Limit write rate (IO per second) to a device (e.g. --device-write-iops=/dev/sda:1000)", + ) + createFlags.StringSlice( + "dns", []string{}, + "Set custom DNS servers", + ) + createFlags.StringSlice( + "dns-opt", []string{}, + "Set custom DNS options", + ) + createFlags.StringSlice( + "dns-search", []string{}, + "Set custom DNS search domains", + ) + createFlags.String( + "entrypoint", "", + "Overwrite the default ENTRYPOINT of the image", + ) + createFlags.StringSliceP( + "env", "e", []string{}, + "Set environment variables in container", + ) + createFlags.StringSlice( + "env-file", []string{}, + "Read in a file of environment variables", + ) + createFlags.StringSlice( + "expose", []string{}, + "Expose a port or a range of ports (default [])", + ) + createFlags.StringSlice( + "gidmap", []string{}, + "GID map to use for the user namespace", + ) + createFlags.StringSlice( + "group-add", []string{}, + "Add additional groups to join (default [])", + ) + createFlags.Bool( + "help", false, "", + ) + + createFlags.StringP( + "hostname", "h", "", + "Set container hostname", + ) + createFlags.String( + "image-volume", "bind", + "Tells podman how to handle the builtin image volumes. The options are: 'bind', 'tmpfs', or 'ignore' (default 'bind')", + ) + createFlags.Bool( + "init", false, + "Run an init binary inside the container that forwards signals and reaps processes", + ) + createFlags.String( + "init-path", "", // Do not use the Value field for setting the default value to determine user input (i.e., non-empty string) - Usage: fmt.Sprintf("Path to the container-init binary (default: %q)", libpod.DefaultInitPath), - }, - cli.BoolFlag{ - Name: "interactive, i", - Usage: "Keep STDIN open even if not attached", - }, - cli.StringFlag{ - Name: "ip", - Usage: "Specify a static IPv4 address for the container", - }, - cli.StringFlag{ - Name: "ipc", - Usage: "IPC namespace to use", - }, - cli.StringFlag{ - Name: "kernel-memory", - Usage: "Kernel memory limit (format: `<number>[<unit>]`, where unit = b, k, m or g)", - }, - cli.StringSliceFlag{ - Name: "label", - Usage: "Set metadata on container (default [])", - }, - cli.StringSliceFlag{ - Name: "label-file", - Usage: "Read in a line delimited file of labels (default [])", - }, - cli.StringFlag{ - Name: "log-driver", - Usage: "Logging driver for the container", - }, - cli.StringSliceFlag{ - Name: "log-opt", - Usage: "Logging driver options (default [])", - }, - cli.StringFlag{ - Name: "mac-address", - Usage: "Container MAC address (e.g. 92:d0:c6:0a:29:33), not currently supported", - }, - cli.StringFlag{ - Name: "memory, m", - Usage: "Memory limit (format: <number>[<unit>], where unit = b, k, m or g)", - }, - cli.StringFlag{ - Name: "memory-reservation", - Usage: "Memory soft limit (format: <number>[<unit>], where unit = b, k, m or g)", - }, - cli.StringFlag{ - Name: "memory-swap", - Usage: "Swap limit equal to memory plus swap: '-1' to enable unlimited swap", - }, - cli.Int64Flag{ - Name: "memory-swappiness", - Usage: "Tune container memory swappiness (0 to 100) (default -1)", - Value: -1, - }, - cli.StringFlag{ - Name: "name", - Usage: "Assign a name to the container", - }, - cli.StringFlag{ - Name: "net, network", - Usage: "Connect a container to a network", - Value: getDefaultNetwork(), - }, - cli.BoolFlag{ - Name: "oom-kill-disable", - Usage: "Disable OOM Killer", - }, - cli.StringFlag{ - Name: "oom-score-adj", - Usage: "Tune the host's OOM preferences (-1000 to 1000)", - }, - cli.StringFlag{ - Name: "pid", - Usage: "PID namespace to use", - }, - cli.Int64Flag{ - Name: "pids-limit", - Usage: "Tune container pids limit (set -1 for unlimited)", - }, - cli.StringFlag{ - Name: "pod", - Usage: "Run container in an existing pod", - }, - cli.BoolFlag{ - Name: "privileged", - Usage: "Give extended privileges to container", - }, - cli.StringSliceFlag{ - Name: "publish, p", - Usage: "Publish a container's port, or a range of ports, to the host (default [])", - }, - cli.BoolFlag{ - Name: "publish-all, P", - Usage: "Publish all exposed ports to random ports on the host interface", - }, - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Suppress output information when pulling images", - }, - cli.BoolFlag{ - Name: "read-only", - Usage: "Make containers root filesystem read-only", - }, - cli.StringFlag{ - Name: "restart", - Usage: "Restart is not supported. Please use a systemd unit file for restart", - }, - cli.BoolFlag{ - Name: "rm", - Usage: "Remove container (and pod if created) after exit", - }, - cli.BoolFlag{ - Name: "rootfs", - Usage: "The first argument is not an image but the rootfs to the exploded container", - }, - cli.StringSliceFlag{ - Name: "security-opt", - Usage: "Security Options (default [])", - }, - cli.StringFlag{ - Name: "shm-size", - Usage: "Size of `/dev/shm`. The format is `<number><unit>`.", - Value: "65536k", - }, - cli.StringFlag{ - Name: "stop-signal", - Usage: "Signal to stop a container. Default is SIGTERM", - }, - cli.IntFlag{ - Name: "stop-timeout", - Usage: "Timeout (in seconds) to stop a container. Default is 10", - Value: libpod.CtrRemoveTimeout, - }, - cli.StringSliceFlag{ - Name: "storage-opt", - Usage: "Storage driver options per container (default [])", - }, - cli.StringFlag{ - Name: "subgidname", - Usage: "Name of range listed in /etc/subgid for use in user namespace", - }, - cli.StringFlag{ - Name: "subuidname", - Usage: "Name of range listed in /etc/subuid for use in user namespace", - }, + fmt.Sprintf("Path to the container-init binary (default: %q)", libpod.DefaultInitPath), + ) + createFlags.BoolP( + "interactive", "i", false, + "Keep STDIN open even if not attached", + ) + createFlags.String( + "ip", "", + "Specify a static IPv4 address for the container", + ) + createFlags.String( + "ipc", "", + "IPC namespace to use", + ) + createFlags.String( + "kernel-memory", "", + "Kernel memory limit (format: `<number>[<unit>]`, where unit = b, k, m or g)", + ) + createFlags.StringSlice( + "label", []string{}, + "Set metadata on container (default [])", + ) + createFlags.StringSlice( + "label-file", []string{}, + "Read in a line delimited file of labels (default [])", + ) + createFlags.String( + "log-driver", "", + "Logging driver for the container", + ) + createFlags.StringSlice( + "log-opt", []string{}, + "Logging driver options (default [])", + ) + createFlags.String( + "mac-address", "", + "Container MAC address (e.g. 92:d0:c6:0a:29:33), not currently supported", + ) + createFlags.StringP( + "memory", "m", "", + "Memory limit (format: <number>[<unit>], where unit = b, k, m or g)", + ) + createFlags.String( + "memory-reservation", "", + "Memory soft limit (format: <number>[<unit>], where unit = b, k, m or g)", + ) + createFlags.String( + "memory-swap", "", + "Swap limit equal to memory plus swap: '-1' to enable unlimited swap", + ) + createFlags.Int64( + "memory-swappiness", -1, + "Tune container memory swappiness (0 to 100) (default -1)", + ) + createFlags.String( + "name", "", + "Assign a name to the container", + ) + createFlags.String( + "net", getDefaultNetwork(), + "Connect a container to a network", + ) + createFlags.String( + "network", getDefaultNetwork(), + "Connect a container to a network", + ) + createFlags.Bool( + "oom-kill-disable", false, + "Disable OOM Killer", + ) + createFlags.Int( + "oom-score-adj", 0, + "Tune the host's OOM preferences (-1000 to 1000)", + ) + createFlags.String( + "pid", "", + "PID namespace to use", + ) + createFlags.Int64( + "pids-limit", 0, + "Tune container pids limit (set -1 for unlimited)", + ) + createFlags.String( + "pod", "", + "Run container in an existing pod", + ) + createFlags.Bool( + "privileged", false, + "Give extended privileges to container", + ) + createFlags.StringSliceP( + "publish", "p", []string{}, + "Publish a container's port, or a range of ports, to the host (default [])", + ) + createFlags.BoolP( + "publish-all", "P", false, + "Publish all exposed ports to random ports on the host interface", + ) + createFlags.BoolP( + "quiet", "q", false, + "Suppress output information when pulling images", + ) + createFlags.Bool( + "read-only", false, + "Make containers root filesystem read-only", + ) + createFlags.String( + "restart", "", + "Restart is not supported. Please use a systemd unit file for restart", + ) + createFlags.Bool( + "rm", false, + "Remove container (and pod if created) after exit", + ) + createFlags.Bool( + "rootfs", false, + "The first argument is not an image but the rootfs to the exploded container", + ) + createFlags.StringArray( + "security-opt", []string{}, + "Security Options (default [])", + ) + createFlags.String( + "shm-size", "65536k", + "Size of `/dev/shm`. The format is `<number><unit>`", + ) + createFlags.String( + "stop-signal", "", + "Signal to stop a container. Default is SIGTERM", + ) + createFlags.Int( + "stop-timeout", libpod.CtrRemoveTimeout, + "Timeout (in seconds) to stop a container. Default is 10", + ) + createFlags.StringSlice( + "storage-opt", []string{}, + "Storage driver options per container (default [])", + ) + createFlags.String( + "subgidname", "", + "Name of range listed in /etc/subgid for use in user namespace", + ) + createFlags.String( + "subuidname", "", + "Name of range listed in /etc/subuid for use in user namespace", + ) - cli.StringSliceFlag{ - Name: "sysctl", - Usage: "Sysctl options (default [])", - }, - cli.BoolTFlag{ - Name: "systemd", - Usage: "Run container in systemd mode if the command executable is systemd or init", - }, - cli.StringSliceFlag{ - Name: "tmpfs", - Usage: "Mount a temporary filesystem (`tmpfs`) into a container (default [])", - }, - cli.BoolFlag{ - Name: "tty, t", - Usage: "Allocate a pseudo-TTY for container", - }, - cli.StringSliceFlag{ - Name: "uidmap", - Usage: "UID map to use for the user namespace", - }, - cli.StringSliceFlag{ - Name: "ulimit", - Usage: "Ulimit options (default [])", - }, - cli.StringFlag{ - Name: "user, u", - Usage: "Username or UID (format: <name|uid>[:<group|gid>])", - }, - cli.StringFlag{ - Name: "userns", - Usage: "User namespace to use", - }, - cli.StringFlag{ - Name: "uts", - Usage: "UTS namespace to use", - }, - cli.StringSliceFlag{ - Name: "mount", - Usage: "Attach a filesystem mount to the container (default [])", - }, - cli.StringSliceFlag{ - Name: "volume, v", - Usage: "Bind mount a volume into the container (default [])", - }, - cli.StringSliceFlag{ - Name: "volumes-from", - Usage: "Mount volumes from the specified container(s) (default [])", - }, - WorkDirFlag, + createFlags.StringSlice( + "sysctl", []string{}, + "Sysctl options (default [])", + ) + createFlags.Bool( + "systemd", true, + "Run container in systemd mode if the command executable is systemd or init", + ) + createFlags.StringSlice( + "tmpfs", []string{}, + "Mount a temporary filesystem (`tmpfs`) into a container (default [])", + ) + createFlags.BoolP( + "tty", "t", false, + "Allocate a pseudo-TTY for container", + ) + createFlags.StringSlice( + "uidmap", []string{}, + "UID map to use for the user namespace", + ) + createFlags.StringSlice( + "ulimit", []string{}, + "Ulimit options (default [])", + ) + createFlags.StringP( + "user", "u", "", + "Username or UID (format: <name|uid>[:<group|gid>])", + ) + createFlags.String( + "userns", "", + "User namespace to use", + ) + createFlags.String( + "uts", "", + "UTS namespace to use", + ) + createFlags.StringArray( + "mount", []string{}, + "Attach a filesystem mount to the container (default [])", + ) + createFlags.StringArrayP( + "volume", "v", []string{}, + "Bind mount a volume into the container (default [])", + ) + createFlags.StringSlice( + "volumes-from", []string{}, + "Mount volumes from the specified container(s) (default [])", + ) + createFlags.StringP( + "workdir", "w", "", + "Working directory inside the container", + ) } -func getFormat(c *cli.Context) (string, error) { +func getFormat(c *cliconfig.PodmanCommand) (string, error) { format := strings.ToLower(c.String("format")) if strings.HasPrefix(format, buildah.OCI) { return buildah.OCIv1ImageManifest, nil @@ -541,13 +498,6 @@ func getFormat(c *cli.Context) (string, error) { return "", errors.Errorf("unrecognized image type %q", format) } -func sortFlags(flags []cli.Flag) []cli.Flag { - sort.Slice(flags, func(i, j int) bool { - return strings.Compare(flags[i].GetName(), flags[j].GetName()) < 0 - }) - return flags -} - func getAuthFile(authfile string) string { if authfile != "" { return authfile @@ -562,3 +512,27 @@ func scrubServer(server string) string { server = strings.TrimPrefix(server, "https://") return strings.TrimPrefix(server, "http://") } + +// UsageTemplate returns the usage template for podman commands +// This blocks the desplaying of the global options. The main podman +// command should not use this. +func UsageTemplate() string { + return `Usage:{{if .Runnable}} + {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} + + {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}} + +Aliases: + {{.NameAndAliases}}{{end}}{{if .HasExample}} + +Examples: + {{.Example}}{{end}}{{if .HasAvailableSubCommands}} + +Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}} + {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} + +Flags: +{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} +{{end}} +` +} |