Skip to content

Commit

Permalink
make argparse output nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Jan 23, 2025
1 parent 2ac7d5a commit 115670e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
12 changes: 11 additions & 1 deletion dlt/cli/_dlt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Sequence, Type, cast, List, Dict
import argparse
import click
import rich_argparse

from dlt.version import __version__
from dlt.common.runners import Venv
Expand Down Expand Up @@ -102,7 +103,6 @@ def __call__(
def main() -> int:
parser = argparse.ArgumentParser(
description="Creates, adds, inspects and deploys dlt pipelines.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--version", action="version", version="%(prog)s {version}".format(version=__version__)
Expand Down Expand Up @@ -146,6 +146,16 @@ def main() -> int:
command.configure_parser(command_parser)
installed_commands[command.command] = command

# recursively add formatter class
def add_formatter_class(parser: argparse.ArgumentParser) -> None:
parser.formatter_class = rich_argparse.RichHelpFormatter
for action in parser._actions:
if isinstance(action, argparse._SubParsersAction):
for _subcmd, subparser in action.choices.items():
add_formatter_class(subparser)

add_formatter_class(parser)

args = parser.parse_args()

if Venv.is_virtual_env() and not Venv.is_venv_activated():
Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ db-dtypes = { version = ">=1.2.0", optional = true }
pyiceberg = { version = ">=0.8.1", optional = true }
databricks-sdk = {version = ">=0.38.0", optional = true}
pywin32 = {version = ">=306", optional = true, platform = "win32"}
rich-argparse = "^1.6.0"

[tool.poetry.extras]
gcp = ["grpcio", "google-cloud-bigquery", "db-dtypes", "gcsfs"]
Expand Down

0 comments on commit 115670e

Please sign in to comment.