mik-laj commented on a change in pull request #13234:
URL: https://github.com/apache/airflow/pull/13234#discussion_r549331159
##########
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)
+ parser.add_argument(
+ PACKAGES,
+ help=textwrap.dedent(
+ """provide packages for setup.py.
+Choose from the above available packages."""
+ ),
+ )
+ parser.add_argument(
+ VERSION_SUFFIX,
+ metavar="SUFFIX",
+ help=textwrap.dedent(
+ """adds version suffix to version of the packages.
+Only useful when generating RC candidates for PyPI."""
+ ),
+ )
+
+ subparsers = parser.add_subparsers(dest="cmd")
+
+ first_param_subparser1 = subparsers.add_parser(LIST_PROVIDERS_PACKAGES,
help="list all provider packages")
+ first_param_subparser1.set_defaults(cmd=LIST_PROVIDERS_PACKAGES)
Review comment:
Do we need these constants? In the [original
issue](https://github.com/apache/airflow/issues/13069), there is a code
attached that proposes to use the function instead. This looks a little more
readable as the docstring can then be used as a command description
https://gist.github.com/mik-laj/ff008718fc6cec9fe929731b8c62d6f8
----------------------------------------------------------------
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]