Skip to content

Commit 9cbf99a

Browse files
committed
Renamed AP_COMMAND_ATTR_SPEC to ARGPARSE_COMMAND_ATTR_SPEC to be more specific.
1 parent 0cf8c03 commit 9cbf99a

6 files changed

Lines changed: 17 additions & 17 deletions

File tree

cmd2/annotated.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def do_paint(
213213
from . import constants
214214
from .argparse_utils import (
215215
DEFAULT_ARGUMENT_PARSER,
216-
ApCommandSpec,
216+
ArgparseCommandSpec,
217217
Cmd2ArgumentParser,
218218
SubcommandSpec,
219219
)
@@ -2329,11 +2329,11 @@ def cmd_wrapper(*args: Any, **kwargs: Any) -> bool | None:
23292329
)
23302330
return result
23312331

2332-
ap_command_spec = ApCommandSpec(
2332+
argparse_command_spec = ArgparseCommandSpec(
23332333
parser_source=parser_builder,
23342334
preserve_quotes=preserve_quotes,
23352335
)
2336-
setattr(cmd_wrapper, constants.AP_COMMAND_ATTR_SPEC, ap_command_spec)
2336+
setattr(cmd_wrapper, constants.ARGPARSE_COMMAND_ATTR_SPEC, argparse_command_spec)
23372337

23382338
return cmd_wrapper
23392339

cmd2/argparse_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def get_choices(self) -> Choices:
292292

293293

294294
@dataclass(kw_only=True)
295-
class ApCommandSpec:
295+
class ArgparseCommandSpec:
296296
"""Metadata for an argparse-based command function.
297297
298298
:param parser_source: an existing Cmd2ArgumentParser instance or a factory

cmd2/cmd2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
from . import rich_utils as ru
112112
from . import string_utils as su
113113
from .argparse_utils import (
114-
ApCommandSpec,
114+
ArgparseCommandSpec,
115115
Cmd2ArgumentParser,
116116
ParserSource,
117117
SubcommandRecord,
@@ -281,7 +281,7 @@ def get(self, command_method: BoundCommandFunc) -> Cmd2ArgumentParser | None:
281281
return None
282282
command = command_method.__name__[len(COMMAND_FUNC_PREFIX) :]
283283

284-
spec: ApCommandSpec | None = getattr(command_method, constants.AP_COMMAND_ATTR_SPEC, None)
284+
spec: ArgparseCommandSpec | None = getattr(command_method, constants.ARGPARSE_COMMAND_ATTR_SPEC, None)
285285
if spec is None:
286286
return None
287287

@@ -2530,7 +2530,7 @@ def _perform_completion(
25302530

25312531
if command_func is not None and argparser is not None:
25322532
# Get arguments for complete()
2533-
spec: ApCommandSpec = getattr(command_func, constants.AP_COMMAND_ATTR_SPEC)
2533+
spec: ArgparseCommandSpec = getattr(command_func, constants.ARGPARSE_COMMAND_ATTR_SPEC)
25342534
cmd_set = self.find_commandset_for_command(command)
25352535

25362536
# Create the argparse completer

cmd2/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def cmd2_public_attr_name(name: str) -> str:
7272
# Attached to a command function; defines its help section category
7373
COMMAND_ATTR_HELP_CATEGORY = cmd2_private_attr_name("help_category")
7474

75-
# Attached to an argparse-based command function; defines its ApCommandSpec instance
76-
AP_COMMAND_ATTR_SPEC = cmd2_private_attr_name("ap_command_spec")
75+
# Attached to an argparse-based command function; defines its ArgparseCommandSpec instance
76+
ARGPARSE_COMMAND_ATTR_SPEC = cmd2_private_attr_name("argparse_command_spec")
7777

7878
# Attached to a subcommand function; defines its SubcommandSpec instance
7979
SUBCOMMAND_ATTR_SPEC = cmd2_private_attr_name("subcommand_spec")

cmd2/decorators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from . import constants
1818
from .argparse_utils import (
19-
ApCommandSpec,
19+
ArgparseCommandSpec,
2020
ClassParamParserFactory,
2121
Cmd2ArgumentParser,
2222
NoParamParserFactory,
@@ -366,11 +366,11 @@ def cmd_wrapper(*args: Any, **kwargs: Any) -> bool | None:
366366

367367
command_name = func.__name__[len(constants.COMMAND_FUNC_PREFIX) :]
368368

369-
spec = ApCommandSpec(
369+
spec = ArgparseCommandSpec(
370370
parser_source=parser_source,
371371
preserve_quotes=preserve_quotes,
372372
)
373-
setattr(cmd_wrapper, constants.AP_COMMAND_ATTR_SPEC, spec)
373+
setattr(cmd_wrapper, constants.ARGPARSE_COMMAND_ATTR_SPEC, spec)
374374

375375
return cmd_wrapper
376376

tests/test_annotated.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ class MyCompleter(ArgparseCompleter):
11211121
@with_annotated(ap_completer_type=MyCompleter)
11221122
def do_run(self, name: str) -> None: ...
11231123

1124-
builder = getattr(do_run, constants.AP_COMMAND_ATTR_SPEC).parser_source
1124+
builder = getattr(do_run, constants.ARGPARSE_COMMAND_ATTR_SPEC).parser_source
11251125
assert builder().ap_completer_type is MyCompleter
11261126

11271127
def test_ap_completer_type_threads_to_subcommand(self) -> None:
@@ -3005,7 +3005,7 @@ def _base_parser(**subcommand_kwargs):
30053005
@with_annotated(base_command=True, **subcommand_kwargs)
30063006
def do_root(self, cmd2_subcommand_func) -> None: ...
30073007

3008-
builder = getattr(do_root, constants.AP_COMMAND_ATTR_SPEC).parser_source
3008+
builder = getattr(do_root, constants.ARGPARSE_COMMAND_ATTR_SPEC).parser_source
30093009
return builder()
30103010

30113011
@staticmethod
@@ -3116,7 +3116,7 @@ def do_run(self, name: str) -> None:
31163116
Extra detail.
31173117
"""
31183118

3119-
builder = getattr(do_run, constants.AP_COMMAND_ATTR_SPEC).parser_source
3119+
builder = getattr(do_run, constants.ARGPARSE_COMMAND_ATTR_SPEC).parser_source
31203120
assert builder().description == "Run the thing."
31213121

31223122
def test_subcommand_uses_docstring(self) -> None:
@@ -3213,7 +3213,7 @@ def test_decorator_passes_parser_kwargs(self) -> None:
32133213
@with_annotated(prog="myprog", usage="usage line")
32143214
def do_run(self, name: str) -> None: ...
32153215

3216-
builder = getattr(do_run, constants.AP_COMMAND_ATTR_SPEC).parser_source
3216+
builder = getattr(do_run, constants.ARGPARSE_COMMAND_ATTR_SPEC).parser_source
32173217
parser = builder()
32183218
assert parser.prog == "myprog"
32193219
assert parser.usage == "usage line"
@@ -3323,7 +3323,7 @@ def test_decorator_threads_all_low_level_kwargs(self) -> None:
33233323
)
33243324
def do_run(self, name: str) -> None: ...
33253325

3326-
builder = getattr(do_run, constants.AP_COMMAND_ATTR_SPEC).parser_source
3326+
builder = getattr(do_run, constants.ARGPARSE_COMMAND_ATTR_SPEC).parser_source
33273327
parser = builder()
33283328
assert parser.prefix_chars == "+-"
33293329
assert parser.fromfile_prefix_chars == "@"

0 commit comments

Comments
 (0)