mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Enables port test
Adds port subcommand for containers Updates check for no args when all flag is set. Signed-off-by: Sujil02 <sushah@redhat.com>
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"github.com/cri-o/ocicni/pkg/ocicni"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -28,18 +29,25 @@ var (
|
||||
podman port ctrID 80/tcp
|
||||
podman port --latest 80`,
|
||||
}
|
||||
|
||||
containerPortCommand = &cobra.Command{
|
||||
Use: "port [flags] CONTAINER [PORT]",
|
||||
Short: portCommand.Short,
|
||||
Long: portDescription,
|
||||
RunE: portCommand.RunE,
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
return parse.CheckAllLatestAndCIDFile(cmd, args, true, false)
|
||||
},
|
||||
Example: `podman container port --all
|
||||
podman container port --latest 80`,
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
portOpts entities.ContainerPortOptions
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||
Mode: []entities.EngineMode{entities.ABIMode},
|
||||
Command: portCommand,
|
||||
})
|
||||
flags := portCommand.Flags()
|
||||
func portFlags(flags *pflag.FlagSet) {
|
||||
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() {
|
||||
@ -47,6 +55,26 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||
Mode: []entities.EngineMode{entities.ABIMode},
|
||||
Command: portCommand,
|
||||
})
|
||||
|
||||
flags := portCommand.Flags()
|
||||
portFlags(flags)
|
||||
|
||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||
Mode: []entities.EngineMode{entities.ABIMode},
|
||||
Command: containerPortCommand,
|
||||
Parent: containerCmd,
|
||||
})
|
||||
|
||||
containerPortflags := containerPortCommand.Flags()
|
||||
portFlags(containerPortflags)
|
||||
|
||||
}
|
||||
|
||||
func port(cmd *cobra.Command, args []string) error {
|
||||
var (
|
||||
container string
|
||||
|
@ -30,13 +30,20 @@ func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool
|
||||
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) && (specifiedAll || specifiedLatest) {
|
||||
return errors.Errorf("no arguments are needed with --all or --latest")
|
||||
} else if cidfile && (argLen > 0) && (specifiedAll || specifiedLatest || specifiedCIDFile) {
|
||||
return errors.Errorf("no arguments are needed with --all, --latest or --cidfile")
|
||||
|
||||
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 {
|
||||
|
@ -20,7 +20,6 @@ var _ = Describe("Podman port", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
Skip(v2fail)
|
||||
tempdir, err = CreateTempDirInTempDir()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
|
Reference in New Issue
Block a user