Repository: docker-tow/tow

Issue:
CMD and ENTRYPOINT arrays should stay arrays in tow.sh
```Dockerfile
ENTRYPOINT ["test"]
CMD ["arg1", "arg2"]
```

should be converted to tow.sh

```bash
"test" "arg1" "arg2" "$@"
```

but not to 

```bash
"test" "arg1 arg2" "$@"
```

Discussion:

Patch:
diff --git a/tow/commands/build.py b/tow/commands/build.py
index f072ae0..9343554 100644
--- a/tow/commands/build.py
+++ b/tow/commands/build.py
@@ -31,11 +31,17 @@ class BuildCommand(Command):
         #  Check if you would like to patch Dockerfile in order to use
         #  reconfiguration on run phase
         if namespace.tow_run:
+            command = []
             (entrypoint, cmd) = dockerfile.find_entrypoint_or_cmd()
+            if cmd:
+                command += cmd
+            if entrypoint:
+                command = entrypoint + command
+                command.append("$@")
             templates.process_template("tow.sh.tmpl",
                                        os.path.join(workingdir, "tow.sh"),
-                                       {"entrypoint": entrypoint,
-                                        "cmd": cmd, "mapping": file_mapping,
+                                       {"command": command,
+                                        "mapping": file_mapping,
                                         "volume_name": TOW_VOLUME})
             file_mapping.append(("tow.sh", "/tow.sh", 755))
             dockerfile.replace_entrypoint_or_cmd_by_tow_cmd("sh /tow.sh")
diff --git a/tow/dockerfile.py b/tow/dockerfile.py
index afd1290..7d15b2f 100644
--- a/tow/dockerfile.py
+++ b/tow/dockerfile.py
@@ -60,9 +60,9 @@ class Dockerfile(object):
             # Handle array command
             if command.startswith("[") and command.endswith("]"):
                 command = command[1:-1]
-                return " ".join([sh.strip()[1:-1] for sh in command.split(",")])
+                return [sh.strip()[1:-1] for sh in command.split(",")]
             else:  # It's just shell notation
-                return command.strip()
+                return [command.strip()]
         return None
 
     def envs(self):
diff --git a/tow/templates/tow.sh.tmpl b/tow/templates/tow.sh.tmpl
index 64d612f..9cf076b 100644
--- a/tow/templates/tow.sh.tmpl
+++ b/tow/templates/tow.sh.tmpl
@@ -7,12 +7,4 @@ fi
 
 PATH=$PATH:`pwd`
 
-{% if entrypoint %}
-{% if cmd %}
-"{{entrypoint}}" "{{cmd}}" "$@"
-{% else %}
-"{{entrypoint}}" "$@"
-{% endif %}
-{% else %}
-"{{cmd}}"
-{% endif %}
+{% for cmd in command -%}"{{ cmd }}" {% endfor %}


Test patch:
diff --git a/tests/dockerfile_tests.py b/tests/dockerfile_tests.py
index 160b5f1..00f563a 100644
--- a/tests/dockerfile_tests.py
+++ b/tests/dockerfile_tests.py
@@ -61,22 +61,22 @@ class DockerfileTest(unittest.TestCase):
     def test_find_entrypoint_or_cmd(self):
         d = Dockerfile("Dockerfile")
         d._Dockerfile__dockerfile = ['FROM ubuntu', 'ENTRYPOINT ["/bin/sh"]', 'CMD ["-c"]']
-        self.assertEqual(d.find_entrypoint_or_cmd(), ("/bin/sh", "-c"))
+        self.assertEqual(d.find_entrypoint_or_cmd(), (["/bin/sh"], ["-c"]))
 
     def test_find_entrypoint_or_cmd_shell_style(self):
         d = Dockerfile("Dockerfile")
         d._Dockerfile__dockerfile = ['FROM ubuntu', 'ENTRYPOINT /bin/sh', 'CMD ["-c"]']
-        self.assertEqual(d.find_entrypoint_or_cmd(), ("/bin/sh", "-c"))
+        self.assertEqual(d.find_entrypoint_or_cmd(), (["/bin/sh"], ["-c"]))
 
     def test_find_entrypoint_or_cmd_cmd_only(self):
         d = Dockerfile("Dockerfile")
         d._Dockerfile__dockerfile = ['FROM ubuntu', 'CMD ["/bin/sh", "-c", "-x"]']
-        self.assertEqual(d.find_entrypoint_or_cmd(), (None, "/bin/sh -c -x"))
+        self.assertEqual(d.find_entrypoint_or_cmd(), (None, ["/bin/sh", "-c", "-x"]))
 
     def test_find_entrypoint_or_cmd_entrypoint_only(self):
         d = Dockerfile("Dockerfile")
         d._Dockerfile__dockerfile = ['FROM ubuntu', 'ENTRYPOINT ["/bin/sh"]']
-        self.assertEqual(d.find_entrypoint_or_cmd(), ("/bin/sh", None))
+        self.assertEqual(d.find_entrypoint_or_cmd(), (["/bin/sh"], None))
 
     def test_find_entrypoint_or_cmd_none(self):
         d = Dockerfile("Dockerfile")