From 3d0cdd898c349c736bf08d53acfbb6d2d4b19e2f Mon Sep 17 00:00:00 2001
From: Ed Santiago <santiago@redhat.com>
Date: Wed, 28 Nov 2018 09:35:29 -0700
Subject: [PATCH] pypod create/run: ignore args for container command

Don't try to argparse command-line arguments on the right-hand
side of the image; those are intended for the container command:

   pypodman create fedora ls -l
   pypodman run fedora find / -name foo
   pypodman run fedora bash -c 'echo hi'

If/when `pypodman exec` gets implemented, it should use this too.

Signed-off-by: Ed Santiago <santiago@redhat.com>
---
 contrib/python/pypodman/pypodman/lib/actions/create_action.py | 2 +-
 contrib/python/pypodman/pypodman/lib/actions/run_action.py    | 2 +-
 contrib/python/pypodman/pypodman/lib/podman_parser.py         | 2 ++
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/contrib/python/pypodman/pypodman/lib/actions/create_action.py b/contrib/python/pypodman/pypodman/lib/actions/create_action.py
index d9631763ae..26a312bb18 100644
--- a/contrib/python/pypodman/pypodman/lib/actions/create_action.py
+++ b/contrib/python/pypodman/pypodman/lib/actions/create_action.py
@@ -21,7 +21,7 @@ class Create(AbstractActionBase):
         parser.add_argument('image', nargs=1, help='source image id')
         parser.add_argument(
             'command',
-            nargs='*',
+            nargs=parent.REMAINDER,
             help='command and args to run.',
         )
         parser.set_defaults(class_=cls, method='create')
diff --git a/contrib/python/pypodman/pypodman/lib/actions/run_action.py b/contrib/python/pypodman/pypodman/lib/actions/run_action.py
index a63eb79176..6a6b3cb2c3 100644
--- a/contrib/python/pypodman/pypodman/lib/actions/run_action.py
+++ b/contrib/python/pypodman/pypodman/lib/actions/run_action.py
@@ -21,7 +21,7 @@ class Run(AbstractActionBase):
         parser.add_argument('image', nargs=1, help='source image id.')
         parser.add_argument(
             'command',
-            nargs='*',
+            nargs=parent.REMAINDER,
             help='command and args to run.',
         )
         parser.set_defaults(class_=cls, method='run')
diff --git a/contrib/python/pypodman/pypodman/lib/podman_parser.py b/contrib/python/pypodman/pypodman/lib/podman_parser.py
index 28fb44cf0b..412c8c8fd9 100644
--- a/contrib/python/pypodman/pypodman/lib/podman_parser.py
+++ b/contrib/python/pypodman/pypodman/lib/podman_parser.py
@@ -97,6 +97,8 @@ class PodmanArgumentParser(argparse.ArgumentParser):
 
         actions_parser = self.add_subparsers(
             dest='subparser_name', help='commands')
+        # For create/exec/run: don't process options intended for subcommand
+        actions_parser.REMAINDER = argparse.REMAINDER
 
         # import buried here to prevent import loops
         import pypodman.lib.actions  # pylint: disable=cyclic-import