Skip to content

Commit

Permalink
Bump version, global state fix + TODO notes
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Oct 5, 2022
1 parent 515dd00 commit 86aa11a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions dcargs/_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ def as_str(x: Any) -> Tuple[str, ...]:

# This can be turned off when we don't want rich-based formatting. (notably for
# completion scripts)
#
# TODO: the global state here is gross. Should be revisited.
USE_RICH = True


Expand Down
23 changes: 13 additions & 10 deletions dcargs/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,6 @@ def _cli_impl(
else:
dummy_wrapped = False

# Map a callable to the relevant CLI arguments + subparsers.
parser_definition = _parsers.ParserSpecification.from_callable_or_type(
f,
description=description,
parent_classes=set(), # Used for recursive calls.
parent_type_from_typevar=None, # Used for recursive calls.
default_instance=default_instance_internal, # Overrides for default values.
prefix="", # Used for recursive calls.
)

# Read and fix arguments. If the user passes in --field_name instead of
# --field-name, correct for them.
args = sys.argv[1:] if args is None else args
Expand All @@ -237,6 +227,9 @@ def fix_arg(arg: str) -> str:
# goal, but manual parsing of argv is convenient for turning off formatting.
print_completion = len(args) >= 2 and args[0] == "--dcargs-print-completion"

# Note: setting USE_RICH must happen before the parser specification is generated.
# TODO: revisit this. Ideally we should be able to eliminate the global state
# changes.
completion_shell = None
if print_completion:
completion_shell = args[1]
Expand All @@ -245,6 +238,16 @@ def fix_arg(arg: str) -> str:
else:
_arguments.USE_RICH = True

# Map a callable to the relevant CLI arguments + subparsers.
parser_definition = _parsers.ParserSpecification.from_callable_or_type(
f,
description=description,
parent_classes=set(), # Used for recursive calls.
parent_type_from_typevar=None, # Used for recursive calls.
default_instance=default_instance_internal, # Overrides for default values.
prefix="", # Used for recursive calls.
)

# Generate parser!
with _argparse_formatter.ansi_context():
parser = argparse.ArgumentParser(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcargs"
version = "0.3.17"
version = "0.3.18"
description = "Strongly typed, zero-effort CLI interfaces"
authors = ["brentyi <[email protected]>"]
include = ["./dcargs/**/*"]
Expand Down

0 comments on commit 86aa11a

Please sign in to comment.