summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSujil02 <sushah@redhat.com>2020-05-06 14:39:58 -0400
committerSujil02 <sushah@redhat.com>2020-05-06 16:06:41 -0400
commit2080421cad535947bbc2f70693fe9fec43ae874d (patch)
treed807c8e0b66b9f594e59328313ca120a4025fb3d
parent062c7b8a9411b7d115f85c2df58aeea760b001bc (diff)
downloadpodman-2080421cad535947bbc2f70693fe9fec43ae874d.tar.gz
podman-2080421cad535947bbc2f70693fe9fec43ae874d.tar.bz2
podman-2080421cad535947bbc2f70693fe9fec43ae874d.zip
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>
-rw-r--r--cmd/podman/containers/port.go38
-rw-r--r--cmd/podman/parse/common.go15
-rw-r--r--test/e2e/port_test.go1
3 files changed, 44 insertions, 10 deletions
diff --git a/cmd/podman/containers/port.go b/cmd/podman/containers/port.go
index 2e3386aa9..ec0ddf838 100644
--- a/cmd/podman/containers/port.go
+++ b/cmd/podman/containers/port.go
@@ -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,23 +29,50 @@ 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 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() {
+ _ = flags.MarkHidden("latest")
+ }
+}
+
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
Command: portCommand,
})
+
flags := portCommand.Flags()
- 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")
- }
+ 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 {
diff --git a/cmd/podman/parse/common.go b/cmd/podman/parse/common.go
index a5e9b4fc2..13f425b6d 100644
--- a/cmd/podman/parse/common.go
+++ b/cmd/podman/parse/common.go
@@ -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 {
diff --git a/test/e2e/port_test.go b/test/e2e/port_test.go
index ce31c9ad2..5bb86d558 100644
--- a/test/e2e/port_test.go
+++ b/test/e2e/port_test.go
@@ -20,7 +20,6 @@ var _ = Describe("Podman port", func() {
)
BeforeEach(func() {
- Skip(v2fail)
tempdir, err = CreateTempDirInTempDir()
if err != nil {
os.Exit(1)