mik-laj commented on a change in pull request #13234:
URL: https://github.com/apache/airflow/pull/13234#discussion_r549331656
##########
File path: dev/provider_packages/prepare_provider_packages.py
##########
@@ -1532,70 +1506,92 @@ def copy_readme_and_changelog(provider_package_id: str,
backport_packages: bool)
suffix = ""
provider_names = get_provider_packages()
- possible_first_params = provider_names.copy()
- possible_first_params.append(LIST_PROVIDERS_PACKAGES)
- possible_first_params.append(LIST_BACKPORTABLE_PACKAGES)
- possible_first_params.append(UPDATE_PACKAGE_RELEASE_NOTES)
- possible_first_params.append(GENERATE_SETUP_FILES)
- if len(sys.argv) == 1:
- print(
- """
-ERROR! Missing first param"
-""",
- file=sys.stderr,
- )
- usage()
- sys.exit(1)
- if sys.argv[1] == "--version-suffix":
- if len(sys.argv) < 3:
- print(
+ help_text = textwrap.dedent(
+ """
+ Available packages:
+
"""
-ERROR! --version-suffix needs parameter!
-""",
- file=sys.stderr,
- )
- usage()
- sys.exit(1)
- suffix = sys.argv[2]
- sys.argv = [sys.argv[0]] + sys.argv[3:]
- elif "--help" in sys.argv or "-h" in sys.argv or len(sys.argv) < 2:
- usage()
- sys.exit(0)
+ )
+ out = ""
+ for package in provider_names:
+ out += f"{package} "
+ out_array = textwrap.wrap(out, 80)
- if sys.argv[1] not in possible_first_params:
- print(
- f"""
-ERROR! Wrong first param: {sys.argv[1]}
-""",
- file=sys.stderr,
- )
- usage()
- print()
+ for text in out_array:
+ help_text += f"{text}\n"
+
+ parser = argparse.ArgumentParser(description=help_text,
formatter_class=argparse.RawTextHelpFormatter)
Review comment:
A common practice is to create a get_parser / _get_parser function that
returns this object. This way, the functions are broken down into several parts
and the code is a bit more readable.
----------------------------------------------------------------
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]