|
39 | 39 | class Action(LoggerProperty, ArgparseAction):
|
40 | 40 | """Base for jsonargparse Action classes."""
|
41 | 41 |
|
| 42 | + @property |
| 43 | + def aliases(self): |
| 44 | + return _action_aliases(self) |
| 45 | + |
| 46 | + |
| 47 | +def _action_aliases(self): |
| 48 | + if not hasattr(self, '_aliases'): |
| 49 | + options = {optstr.lstrip('-').replace('-', '_') |
| 50 | + for optstr in self.option_strings} |
| 51 | + options = {opt for opt in options if len(opt) > 1} |
| 52 | + self._aliases = {self.dest} | options |
| 53 | + return self._aliases |
| 54 | + |
42 | 55 |
|
43 | 56 | def _is_branch_key(parser, key: str) -> bool:
|
44 | 57 | root_key = split_key_root(key)[0]
|
@@ -70,10 +83,10 @@ def _find_action_and_subcommand(
|
70 | 83 | actions = [a for a in actions if not isinstance(a, exclude)]
|
71 | 84 | fallback_action = None
|
72 | 85 |
|
73 |
| - ALLOW_ALIAS = True |
74 |
| - |
75 | 86 | for action in actions:
|
76 |
| - if action.dest == dest or (ALLOW_ALIAS and dest in get_alias_dest(action)): |
| 87 | + # _StoreAction seems to break the property |
| 88 | + # if dest in action.aliases: |
| 89 | + if dest in _action_aliases(action): |
77 | 90 | if isinstance(action, _ActionConfigLoad):
|
78 | 91 | fallback_action = action
|
79 | 92 | else:
|
@@ -752,8 +765,5 @@ def handle_subcommands(
|
752 | 765 |
|
753 | 766 |
|
754 | 767 | def get_alias_dest(action):
|
755 |
| - def option_string_to_var(optstr): |
756 |
| - " normalize a cli key as a variable " |
757 |
| - return optstr.lstrip('-').replace('-', '_') |
758 |
| - |
759 |
| - return [option_string_to_var(optstr) for optstr in action.option_strings] |
| 768 | + return [optstr.lstrip('-').replace('-', '_') |
| 769 | + for optstr in action.option_strings] |
0 commit comments