mirror of
https://github.com/containers/podman.git
synced 2025-06-20 09:03:43 +08:00
Merge pull request #6733 from edsantiago/bats_help_extra_args
BATS tests: new too-many-arguments test
This commit is contained in:
@ -22,7 +22,7 @@ var (
|
|||||||
Short: "Create new image based on the changed container",
|
Short: "Create new image based on the changed container",
|
||||||
Long: commitDescription,
|
Long: commitDescription,
|
||||||
RunE: commit,
|
RunE: commit,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.RangeArgs(1, 2),
|
||||||
Example: `podman commit -q --message "committing container to image" reverent_golick image-committed
|
Example: `podman commit -q --message "committing container to image" reverent_golick image-committed
|
||||||
podman commit -q --author "firstName lastName" reverent_golick image-committed
|
podman commit -q --author "firstName lastName" reverent_golick image-committed
|
||||||
podman commit -q --pause=false containerID image-committed
|
podman commit -q --pause=false containerID image-committed
|
||||||
@ -30,7 +30,7 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerCommitCommand = &cobra.Command{
|
containerCommitCommand = &cobra.Command{
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: commitCommand.Args,
|
||||||
Use: commitCommand.Use,
|
Use: commitCommand.Use,
|
||||||
Short: commitCommand.Short,
|
Short: commitCommand.Short,
|
||||||
Long: commitCommand.Long,
|
Long: commitCommand.Long,
|
||||||
@ -82,7 +82,7 @@ func init() {
|
|||||||
|
|
||||||
func commit(cmd *cobra.Command, args []string) error {
|
func commit(cmd *cobra.Command, args []string) error {
|
||||||
container := args[0]
|
container := args[0]
|
||||||
if len(args) > 1 {
|
if len(args) == 2 {
|
||||||
commitOptions.ImageName = args[1]
|
commitOptions.ImageName = args[1]
|
||||||
}
|
}
|
||||||
if !commitOptions.Quiet {
|
if !commitOptions.Quiet {
|
||||||
|
@ -28,7 +28,7 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerExportCommand = &cobra.Command{
|
containerExportCommand = &cobra.Command{
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
Use: exportCommand.Use,
|
Use: exportCommand.Use,
|
||||||
Short: exportCommand.Short,
|
Short: exportCommand.Short,
|
||||||
Long: exportCommand.Long,
|
Long: exportCommand.Long,
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
// podman container _inspect_
|
// podman container _inspect_
|
||||||
inspectCmd = &cobra.Command{
|
inspectCmd = &cobra.Command{
|
||||||
Use: "inspect [flags] CONTAINER",
|
Use: "inspect [flags] CONTAINER [CONTAINER...]",
|
||||||
Short: "Display the configuration of a container",
|
Short: "Display the configuration of a container",
|
||||||
Long: `Displays the low-level information on a container identified by name or ID.`,
|
Long: `Displays the low-level information on a container identified by name or ID.`,
|
||||||
RunE: inspectExec,
|
RunE: inspectExec,
|
||||||
|
@ -23,7 +23,7 @@ var (
|
|||||||
`
|
`
|
||||||
|
|
||||||
mountCommand = &cobra.Command{
|
mountCommand = &cobra.Command{
|
||||||
Use: "mount [flags] [CONTAINER]",
|
Use: "mount [flags] [CONTAINER...]",
|
||||||
Short: "Mount a working container's root filesystem",
|
Short: "Mount a working container's root filesystem",
|
||||||
Long: mountDescription,
|
Long: mountDescription,
|
||||||
RunE: mount,
|
RunE: mount,
|
||||||
|
@ -89,6 +89,9 @@ func port(cmd *cobra.Command, args []string) error {
|
|||||||
container = args[0]
|
container = args[0]
|
||||||
}
|
}
|
||||||
port := ""
|
port := ""
|
||||||
|
if len(args) > 2 {
|
||||||
|
return errors.Errorf("`port` accepts at most 2 arguments")
|
||||||
|
}
|
||||||
if len(args) > 1 && !portOpts.Latest {
|
if len(args) > 1 && !portOpts.Latest {
|
||||||
port = args[1]
|
port = args[1]
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ var (
|
|||||||
topOptions = entities.TopOptions{}
|
topOptions = entities.TopOptions{}
|
||||||
|
|
||||||
topCommand = &cobra.Command{
|
topCommand = &cobra.Command{
|
||||||
Use: "top [flags] CONTAINER [FORMAT-DESCRIPTORS|ARGS]",
|
Use: "top [flags] CONTAINER [FORMAT-DESCRIPTORS|ARGS...]",
|
||||||
Short: "Display the running processes of a container",
|
Short: "Display the running processes of a container",
|
||||||
Long: topDescription,
|
Long: topDescription,
|
||||||
RunE: top,
|
RunE: top,
|
||||||
|
@ -20,7 +20,7 @@ var (
|
|||||||
Short: "Generate systemd units.",
|
Short: "Generate systemd units.",
|
||||||
Long: systemdDescription,
|
Long: systemdDescription,
|
||||||
RunE: systemd,
|
RunE: systemd,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
Example: `podman generate systemd CTR
|
Example: `podman generate systemd CTR
|
||||||
podman generate systemd --new --time 10 CTR
|
podman generate systemd --new --time 10 CTR
|
||||||
podman generate systemd --files --name POD`,
|
podman generate systemd --files --name POD`,
|
||||||
|
@ -45,6 +45,7 @@ var (
|
|||||||
Long: buildDescription,
|
Long: buildDescription,
|
||||||
TraverseChildren: true,
|
TraverseChildren: true,
|
||||||
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 .`,
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
// Command: podman image _inspect_
|
// Command: podman image _inspect_
|
||||||
inspectCmd = &cobra.Command{
|
inspectCmd = &cobra.Command{
|
||||||
Use: "inspect [flags] IMAGE",
|
Use: "inspect [flags] IMAGE [IMAGE...]",
|
||||||
Short: "Display the configuration of an image",
|
Short: "Display the configuration of an image",
|
||||||
Long: `Displays the low-level information of an image identified by name or ID.`,
|
Long: `Displays the low-level information of an image identified by name or ID.`,
|
||||||
RunE: inspectExec,
|
RunE: inspectExec,
|
||||||
|
@ -32,7 +32,7 @@ type listFlagType struct {
|
|||||||
var (
|
var (
|
||||||
// Command: podman image _list_
|
// Command: podman image _list_
|
||||||
listCmd = &cobra.Command{
|
listCmd = &cobra.Command{
|
||||||
Use: "list [FLAGS] [IMAGE]",
|
Use: "list [flags] [IMAGE]",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
Short: "List images in local storage",
|
Short: "List images in local storage",
|
||||||
|
@ -29,10 +29,11 @@ var (
|
|||||||
|
|
||||||
// Command: podman push
|
// Command: podman push
|
||||||
pushCmd = &cobra.Command{
|
pushCmd = &cobra.Command{
|
||||||
Use: "push [flags] SOURCE DESTINATION",
|
Use: "push [flags] SOURCE [DESTINATION]",
|
||||||
Short: "Push an image to a specified destination",
|
Short: "Push an image to a specified destination",
|
||||||
Long: pushDescription,
|
Long: pushDescription,
|
||||||
RunE: imagePush,
|
RunE: imagePush,
|
||||||
|
Args: cobra.RangeArgs(1, 2),
|
||||||
Example: `podman push imageID docker://registry.example.com/repository:tag
|
Example: `podman push imageID docker://registry.example.com/repository:tag
|
||||||
podman push imageID oci-archive:/path/to/layout:image:tag`,
|
podman push imageID oci-archive:/path/to/layout:image:tag`,
|
||||||
}
|
}
|
||||||
@ -45,6 +46,7 @@ var (
|
|||||||
Short: pushCmd.Short,
|
Short: pushCmd.Short,
|
||||||
Long: pushCmd.Long,
|
Long: pushCmd.Long,
|
||||||
RunE: pushCmd.RunE,
|
RunE: pushCmd.RunE,
|
||||||
|
Args: pushCmd.Args,
|
||||||
Example: `podman image push imageID docker://registry.example.com/repository:tag
|
Example: `podman image push imageID docker://registry.example.com/repository:tag
|
||||||
podman image push imageID oci-archive:/path/to/layout:image:tag`,
|
podman image push imageID oci-archive:/path/to/layout:image:tag`,
|
||||||
}
|
}
|
||||||
@ -96,19 +98,8 @@ func pushFlags(flags *pflag.FlagSet) {
|
|||||||
|
|
||||||
// imagePush is implement the command for pushing images.
|
// imagePush is implement the command for pushing images.
|
||||||
func imagePush(cmd *cobra.Command, args []string) error {
|
func imagePush(cmd *cobra.Command, args []string) error {
|
||||||
var source, destination string
|
source := args[0]
|
||||||
switch len(args) {
|
destination := args[len(args)-1]
|
||||||
case 1:
|
|
||||||
source = args[0]
|
|
||||||
destination = args[0]
|
|
||||||
case 2:
|
|
||||||
source = args[0]
|
|
||||||
destination = args[1]
|
|
||||||
case 0:
|
|
||||||
fallthrough
|
|
||||||
default:
|
|
||||||
return errors.New("push requires at least one image name, or optionally a second to specify a different destination")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TLS verification in c/image is controlled via a `types.OptionalBool`
|
// TLS verification in c/image is controlled via a `types.OptionalBool`
|
||||||
// which allows for distinguishing among set-true, set-false, unspecified
|
// which allows for distinguishing among set-true, set-false, unspecified
|
||||||
|
@ -23,8 +23,8 @@ var (
|
|||||||
saveDescription = `Save an image to docker-archive or oci-archive on the local machine. Default is docker-archive.`
|
saveDescription = `Save an image to docker-archive or oci-archive on the local machine. Default is docker-archive.`
|
||||||
|
|
||||||
saveCommand = &cobra.Command{
|
saveCommand = &cobra.Command{
|
||||||
Use: "save [flags] IMAGE",
|
Use: "save [flags] IMAGE [IMAGE...]",
|
||||||
Short: "Save image to an archive",
|
Short: "Save image(s) to an archive",
|
||||||
Long: saveDescription,
|
Long: saveDescription,
|
||||||
RunE: save,
|
RunE: save,
|
||||||
Args: func(cmd *cobra.Command, args []string) error {
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -18,6 +18,7 @@ var (
|
|||||||
Short: "Display trust policy for the system",
|
Short: "Display trust policy for the system",
|
||||||
Long: showTrustDescription,
|
Long: showTrustDescription,
|
||||||
RunE: showTrust,
|
RunE: showTrust,
|
||||||
|
Args: cobra.MaximumNArgs(1),
|
||||||
Example: "",
|
Example: "",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,7 @@ 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,
|
TraverseChildren: true,
|
||||||
|
@ -20,7 +20,7 @@ var (
|
|||||||
Example: `podman manifest create mylist:v1.11
|
Example: `podman manifest create mylist:v1.11
|
||||||
podman manifest create mylist:v1.11 arch-specific-image-to-add
|
podman manifest create mylist:v1.11 arch-specific-image-to-add
|
||||||
podman manifest create --all mylist:v1.11 transport:tagged-image-to-add`,
|
podman manifest create --all mylist:v1.11 transport:tagged-image-to-add`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.RangeArgs(1, 2),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"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/containers/libpod/pkg/network"
|
"github.com/containers/libpod/pkg/network"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
@ -20,6 +19,7 @@ var (
|
|||||||
Short: "network create",
|
Short: "network create",
|
||||||
Long: networkCreateDescription,
|
Long: networkCreateDescription,
|
||||||
RunE: networkCreate,
|
RunE: networkCreate,
|
||||||
|
Args: cobra.MaximumNArgs(1),
|
||||||
Example: `podman network create podman1`,
|
Example: `podman network create podman1`,
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
registry.ParentNSRequired: "",
|
registry.ParentNSRequired: "",
|
||||||
@ -62,14 +62,10 @@ func networkCreate(cmd *cobra.Command, args []string) error {
|
|||||||
if err := network.IsSupportedDriver(networkCreateOptions.Driver); err != nil {
|
if err := network.IsSupportedDriver(networkCreateOptions.Driver); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(args) > 1 {
|
|
||||||
return errors.Errorf("only one network can be created at a time")
|
|
||||||
}
|
|
||||||
if len(args) > 0 && !define.NameRegex.MatchString(args[0]) {
|
|
||||||
return define.RegexError
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
if !define.NameRegex.MatchString(args[0]) {
|
||||||
|
return define.RegexError
|
||||||
|
}
|
||||||
name = args[0]
|
name = args[0]
|
||||||
}
|
}
|
||||||
response, err := registry.ContainerEngine().NetworkCreate(registry.Context(), name, networkCreateOptions)
|
response, err := registry.ContainerEngine().NetworkCreate(registry.Context(), name, networkCreateOptions)
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
networkinspectDescription = `Inspect network`
|
networkinspectDescription = `Inspect network`
|
||||||
networkinspectCommand = &cobra.Command{
|
networkinspectCommand = &cobra.Command{
|
||||||
Use: "inspect NETWORK [NETWORK...] [flags] ",
|
Use: "inspect [flags] NETWORK [NETWORK...]",
|
||||||
Short: "network inspect",
|
Short: "network inspect",
|
||||||
Long: networkinspectDescription,
|
Long: networkinspectDescription,
|
||||||
RunE: networkInspect,
|
RunE: networkInspect,
|
||||||
|
@ -22,7 +22,7 @@ var (
|
|||||||
topOptions = entities.PodTopOptions{}
|
topOptions = entities.PodTopOptions{}
|
||||||
|
|
||||||
topCommand = &cobra.Command{
|
topCommand = &cobra.Command{
|
||||||
Use: "top [flags] POD [FORMAT-DESCRIPTORS|ARGS]",
|
Use: "top [flags] POD [FORMAT-DESCRIPTORS|ARGS...]",
|
||||||
Short: "Display the running processes of containers in a pod",
|
Short: "Display the running processes of containers in a pod",
|
||||||
Long: topDescription,
|
Long: topDescription,
|
||||||
RunE: top,
|
RunE: top,
|
||||||
|
@ -29,7 +29,7 @@ var (
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
connectionCmd = &cobra.Command{
|
connectionCmd = &cobra.Command{
|
||||||
Use: "connection [flags] destination",
|
Use: "connection [flags] DESTINATION",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
Long: `Store ssh destination information in podman configuration.
|
Long: `Store ssh destination information in podman configuration.
|
||||||
"destination" is of the form [user@]hostname or
|
"destination" is of the form [user@]hostname or
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
unshareDescription = "Runs a command in a modified user namespace."
|
unshareDescription = "Runs a command in a modified user namespace."
|
||||||
unshareCommand = &cobra.Command{
|
unshareCommand = &cobra.Command{
|
||||||
Use: "unshare [flags] [COMMAND [ARG]]",
|
Use: "unshare [flags] [COMMAND [ARG ...]]",
|
||||||
Short: "Run a command in a modified user namespace",
|
Short: "Run a command in a modified user namespace",
|
||||||
Long: unshareDescription,
|
Long: unshareDescription,
|
||||||
RunE: unshare,
|
RunE: unshare,
|
||||||
|
@ -25,8 +25,11 @@ func SubCommandExists(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
// IDOrLatestArgs used to validate a nameOrId was provided or the "--latest" flag
|
// IDOrLatestArgs used to validate a nameOrId was provided or the "--latest" flag
|
||||||
func IDOrLatestArgs(cmd *cobra.Command, args []string) error {
|
func IDOrLatestArgs(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) > 1 || (len(args) == 0 && !cmd.Flag("latest").Changed) {
|
if len(args) > 1 {
|
||||||
return fmt.Errorf("`%s` requires a name, id or the \"--latest\" flag", 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())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ function podman_commands() {
|
|||||||
|
|
||||||
function check_help() {
|
function check_help() {
|
||||||
local count=0
|
local count=0
|
||||||
local subcommands_found=0
|
local -A found
|
||||||
|
|
||||||
for cmd in $(podman_commands "$@"); do
|
for cmd in $(podman_commands "$@"); do
|
||||||
# Human-readable podman command string, with multiple spaces collapsed
|
# Human-readable podman command string, with multiple spaces collapsed
|
||||||
@ -44,24 +44,37 @@ function check_help() {
|
|||||||
|
|
||||||
# If usage ends in '[command]', recurse into subcommands
|
# If usage ends in '[command]', recurse into subcommands
|
||||||
if expr "$usage" : '.*\[command\]$' >/dev/null; then
|
if expr "$usage" : '.*\[command\]$' >/dev/null; then
|
||||||
subcommands_found=$(expr $subcommands_found + 1)
|
found[subcommands]=1
|
||||||
check_help "$@" $cmd
|
check_help "$@" $cmd
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If usage ends in '[flag]', command takes no more arguments.
|
# We had someone write upper-case '[FLAGS]' once. Prevent it.
|
||||||
# Confirm that by running with 'invalid-arg' and expecting failure.
|
if expr "$usage" : '.*\[FLAG' >/dev/null; then
|
||||||
if expr "$usage" : '.*\[flags\]$' >/dev/null; then
|
die "'flags' string must be lower-case in usage: $usage"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# We had someone do 'podman foo ARG [flags]' one time. Yeah, no.
|
||||||
|
if expr "$usage" : '.*[A-Z].*\[flag' >/dev/null; then
|
||||||
|
die "'flags' must precede arguments in usage: $usage"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If usage lists no arguments (strings in ALL CAPS), confirm
|
||||||
|
# by running with 'invalid-arg' and expecting failure.
|
||||||
|
if ! expr "$usage" : '.*[A-Z]' >/dev/null; then
|
||||||
if [ "$cmd" != "help" ]; then
|
if [ "$cmd" != "help" ]; then
|
||||||
dprint "$command_string invalid-arg"
|
dprint "$command_string invalid-arg"
|
||||||
run_podman 125 "$@" $cmd invalid-arg
|
run_podman 125 "$@" $cmd invalid-arg
|
||||||
is "$output" "Error: .* takes no arguments" \
|
is "$output" "Error: .* takes no arguments" \
|
||||||
"'$command_string' with extra (invalid) arguments"
|
"'$command_string' with extra (invalid) arguments"
|
||||||
fi
|
fi
|
||||||
|
found[takes_no_args]=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 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
|
# The expression here is 'first capital letter is not in [BRACKETS]'.
|
||||||
|
# It is intended to handle 'podman foo [flags] ARG' but not ' [ARG]'.
|
||||||
|
if expr "$usage" : '[^A-Z]\+ [A-Z]' >/dev/null; then
|
||||||
# Exceptions: these commands don't work rootless
|
# Exceptions: these commands don't work rootless
|
||||||
if is_rootless; then
|
if is_rootless; then
|
||||||
# "pause is not supported for rootless containers"
|
# "pause is not supported for rootless containers"
|
||||||
@ -80,6 +93,31 @@ function check_help() {
|
|||||||
run_podman 125 "$@" $cmd </dev/null
|
run_podman 125 "$@" $cmd </dev/null
|
||||||
is "$output" "Error:.* \(require\|specif\|must\|provide\|need\|choose\|accepts\)" \
|
is "$output" "Error:.* \(require\|specif\|must\|provide\|need\|choose\|accepts\)" \
|
||||||
"'$command_string' without required arg"
|
"'$command_string' without required arg"
|
||||||
|
|
||||||
|
found[required_args]=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Commands with fixed number of arguments (i.e. no ellipsis): count
|
||||||
|
# the required args, then invoke with one extra. We should get a
|
||||||
|
# usage error.
|
||||||
|
if ! expr "$usage" : ".*\.\.\."; then
|
||||||
|
# "podman help" can take infinite args, so skip that one
|
||||||
|
if [ "$cmd" != "help" ]; then
|
||||||
|
# Get the args part of the command line; this should be
|
||||||
|
# everything from the first CAPITAL LETTER onward. We
|
||||||
|
# don't actually care about the letter itself, so just
|
||||||
|
# make it 'X'. And we don't care about [OPTIONAL] brackets
|
||||||
|
# either. What we do care about is stuff like 'IMAGE | CTR'
|
||||||
|
# which is actually one argument; convert to 'IMAGE-or-CTR'
|
||||||
|
local rhs=$(sed -e 's/^[^A-Z]\+[A-Z]/X/' -e 's/ | /-or-/g' <<<"$usage")
|
||||||
|
local n_args=$(wc -w <<<"$rhs")
|
||||||
|
|
||||||
|
run_podman 125 "$@" $cmd $(seq --format='x%g' 0 $n_args)
|
||||||
|
is "$output" "Error:.* \(takes no arguments\|requires exactly $n_args arg\|accepts at most\|too many arguments\|accepts $n_args arg(s), received\|accepts between .* and .* arg(s), received \)" \
|
||||||
|
"'$command_string' with >$n_args arguments"
|
||||||
|
|
||||||
|
found[fixed_args]=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
count=$(expr $count + 1)
|
count=$(expr $count + 1)
|
||||||
@ -101,9 +139,14 @@ function check_help() {
|
|||||||
[ $count -gt 0 ] || \
|
[ $count -gt 0 ] || \
|
||||||
die "Internal error: no commands found in 'podman help $@' list"
|
die "Internal error: no commands found in 'podman help $@' list"
|
||||||
|
|
||||||
# At least the top level must have some subcommands
|
# Sanity check: make sure the special loops above triggered at least once.
|
||||||
if [ -z "$*" -a $subcommands_found -eq 0 ]; then
|
# (We've had situations where a typo makes the conditional never run)
|
||||||
die "Internal error: did not find any podman subcommands"
|
if [ -z "$*" ]; then
|
||||||
|
for i in subcommands required_args takes_no_args fixed_args; do
|
||||||
|
if [[ -z ${found[$i]} ]]; then
|
||||||
|
die "Internal error: '$i' subtest did not trigger"
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,10 +107,4 @@ verify_iid_and_name() {
|
|||||||
"Diagnostic from 'podman load' without redirection or -i"
|
"Diagnostic from 'podman load' without redirection or -i"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "podman load - at most 1 arg(s)" {
|
|
||||||
run_podman 125 load 1 2 3
|
|
||||||
is "$output" \
|
|
||||||
"Error: accepts at most 1 arg(s), received 3"
|
|
||||||
}
|
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user