Skip to content

Commit 10961dd

Browse files
authored
Merge pull request #23 from explosion/fix/no-defaullt-handling
2 parents 4d53eda + 3e59ca4 commit 10961dd

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

radicli/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,14 @@ def _add_args(self, parser: ArgumentParser, args: List[ArgparseArg]) -> None:
380380
if arg.id == self.extra_key:
381381
continue
382382
func_args, func_kwargs = arg.to_argparse()
383-
# Suppress all argument defaults and mark options without defaults
384-
# as required
383+
# Suppress all defaults and mark options without defaults as required
385384
if not self.fill_defaults:
386385
func_kwargs["default"] = DEFAULT_PLACEHOLDER
387386
if arg.arg.option:
388387
func_kwargs["required"] = arg.default is DEFAULT_PLACEHOLDER
388+
if arg.help and arg.default is not DEFAULT_PLACEHOLDER:
389+
# Manually add default to help again (now suppressed)
390+
func_kwargs["help"] = f"{arg.help} (default: {arg.default})"
389391
parser.add_argument(*func_args, **func_kwargs)
390392

391393
def _validate(

radicli/parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import argparse
44
import sys
55

6-
from .util import format_arg_help, CliParserError
6+
from .util import format_arg_help, CliParserError, DEFAULT_PLACEHOLDER
77

88

99
class ArgumentParser(argparse.ArgumentParser):
@@ -13,6 +13,8 @@ def error(self, message: str) -> NoReturn:
1313
# Overriding this internal function so we can have more control over how
1414
# errors are handled and (not) masked internally
1515
def _get_value(self, action: argparse.Action, arg_string: str) -> Any:
16+
if arg_string == DEFAULT_PLACEHOLDER:
17+
return DEFAULT_PLACEHOLDER
1618
type_func = self._registry_get("type", action.type, action.type)
1719
if not callable(type_func):
1820
raise argparse.ArgumentError(action, f"{type_func!r} is not callable")

radicli/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def get_arg(
314314
if inspect.isclass(param_type) and issubclass(param_type, Enum):
315315
arg.choices = list(param_type.__members__.keys())
316316
arg.type = lambda value: getattr(param_type, value, value)
317+
arg.has_converter = True
317318
return arg
318319
if not origin:
319320
raise UnsupportedTypeError(param, param_type)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[metadata]
2-
version = 0.0.19
2+
version = 0.0.20
33
description = Radically lightweight command-line interfaces
44
url = https://github.com/explosion/radicli
55
author = Explosion

0 commit comments

Comments
 (0)