Taragolis commented on code in PR #39464:
URL: https://github.com/apache/airflow/pull/39464#discussion_r1593883440


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -225,6 +231,24 @@ def stream_new_logs(last_line_logged, since=0):
             sleep(2)
             last_line_logged, last_timestamp = 
stream_new_logs(last_line_logged, since=last_timestamp)
 
+    @staticmethod
+    def format_args(args: list[str] | str | None) -> list[str] | None:
+        """Retrieve args.
+
+        The args string is parsed to a list. If it starts with ``[``,
+        the string is treated as a Python literal and parsed into a list.
+
+        :param args: args to the docker service
+
+        :return: the args as list
+        """
+        if isinstance(args, str):
+            if args.strip().startswith("["):
+                return ast.literal_eval(args)
+            else:
+                return shlex.split(args)
+        return args

Review Comment:
   I mean, maybe it is even not required, since it not templated field, so user 
have an option to provide it as pure string command
   
   ```python
   DockerSwarmOperator(
       task_id="foo-bar",
       ...
       args="--foo bar --spam --egg",
   )
   ```
   
   Or command list
   
   ```python
   DockerSwarmOperator(
       task_id="foo-bar",
       ...
       args=["--foo", "bar", "--spam", "--egg"],
   )
   ```
   
   But I'm not sure if it handy to provide as json / string representation of 
python list at all
   
   ```python
   DockerSwarmOperator(
       task_id="foo-bar",
       ...
       args='["--foo", "bar", "--spam", "--egg"]',
   )
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to