You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/21 20:04:56 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #7801: Remove arg lookup map in CLIFactory

mik-laj commented on a change in pull request #7801: Remove arg lookup map in CLIFactory
URL: https://github.com/apache/airflow/pull/7801#discussion_r396024646
 
 

 ##########
 File path: airflow/bin/cli.py
 ##########
 @@ -1082,35 +1155,46 @@ def get_long_option(arg):
             """
             Get long option from Arg.flags
             """
-            return cls.args[arg].flags[0] if len(cls.args[arg].flags) == 1 else cls.args[arg].flags[1]
-        positional, optional = partition(lambda x: cls.args[x].flags[0].startswith("-"), args)
+            return arg.flags[0] if len(arg.flags) == 1 else arg.flags[1]
+        positional, optional = partition(lambda x: x.flags[0].startswith("-"), args)
         yield from positional
         yield from sorted(optional, key=lambda x: get_long_option(x).lower())
 
     @classmethod
-    def _add_subcommand(cls, subparsers, sub):
-        dag_parser = False
+    def _add_command(cls, subparsers, sub):
         sub_proc = subparsers.add_parser(
-            sub.get('name') or sub['func'].__name__, help=sub['help']  # type: ignore
+            sub['name'], help=sub['help']
         )
         sub_proc.formatter_class = RawTextHelpFormatter
 
-        subcommands = sub.get('subcommands', [])
-        if subcommands:
-            sub_subparsers = sub_proc.add_subparsers(dest='subcommand')
-            sub_subparsers.required = True
-            for command in sorted(subcommands, key=lambda x: x['name']):
-                cls._add_subcommand(sub_subparsers, command)
+        if 'subcommands' in sub:
+            cls._add_subcommaand(sub, sub_proc)
+        elif 'func' in sub:
+            cls._add_action_command(sub, sub_proc)
         else:
-            for arg in cls.sort_args(sub['args']):
-                if 'dag_id' in arg and dag_parser:
-                    continue
-                arg = cls.args[arg]
-                kwargs = {
-                    f: v
-                    for f, v in vars(arg).items() if f != 'flags' and v}
-                sub_proc.add_argument(*arg.flags, **kwargs)
-            sub_proc.set_defaults(func=sub['func'])
+            raise AirflowException("Invalid command definition.")
+
+    @classmethod
+    def _add_action_command(cls, sub, sub_proc):
 
 Review comment:
   Yes, but in a separate PR. In the next PR I want to replace dictionaries with named tuples.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services