mik-laj commented on a change in pull request #6875: [AIRFLOW-6076] Fix
dag.cli() Key error
URL: https://github.com/apache/airflow/pull/6875#discussion_r362484935
##########
File path: airflow/bin/cli.py
##########
@@ -1028,38 +1025,59 @@ def error(self, message):
help='sub-command help', dest='subcommand')
subparsers.required = True
- subparser_list = cls.dag_subparsers if dag_parser else
cls.subparsers_dict.keys()
- for sub in sorted(subparser_list):
- sub = cls.subparsers_dict[sub]
- cls._add_subcommand(subparsers, sub)
+ for sub in sorted(self.subparsers, key=lambda d: d['name']):
+ self._add_subcommand(subparsers, sub)
return parser
- @classmethod
- def _add_subcommand(cls, subparsers, sub):
- dag_parser = False
+ def _add_subcommand(self, subparsers, sub):
sub_proc = subparsers.add_parser(
sub.get('name') or sub['func'].__name__, help=sub['help'] # type:
ignore
)
sub_proc.formatter_class = RawTextHelpFormatter
- subcommands = sub.get('subcommands', [])
- if subcommands:
+ if 'subcommands' in sub:
+ subcommands = sub.get('subcommands', [])
Review comment:
Can you create functions from the content of this "if"? This will simplify
the understanding of the code, because this function will have one purpose. Do
you think function names now have a good name? Maybe it's worth changing the
name also?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services