Skip to content

Commit 8db70c4

Browse files
authored
Merge branch 'main' into refactor_bottom_toolbar
2 parents 4706ed0 + 54e7766 commit 8db70c4

6 files changed

Lines changed: 1996 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
transforming the raw token while keeping the inferred `type=`/`choices`/completer (e.g.
4949
`preprocess=str.lower` on an `Enum`). The two are mutually exclusive on one parameter and
5050
neither may be combined with a value-less action.
51+
- `@with_annotated` now supports reusable argument blocks: a parameter typed with a `@dataclass`
52+
that subclasses the new `cmd2.ArgumentBlock` trait expands each field into a flat command-line
53+
argument, and the parsed values are reconstructed into a dataclass instance passed to the
54+
command, letting several commands reuse the same fields without duplication. See the
55+
[annotated](docs/features/annotated.md) documentation.
56+
- A command can share an argument block with its subcommands via `cmd2_base_args` /
57+
`cmd2_parent_args` parameters, passing parent-level options down without redeclaring them.
5158

5259
- Breaking Changes
5360
- Renamed the `bottom_toolbar` argument in `Cmd.__init__()` to `enable_bottom_toolbar`.

cmd2/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
rich_utils,
1212
string_utils,
1313
)
14-
from .annotated import with_annotated
14+
from .annotated import (
15+
ArgumentBlock,
16+
with_annotated,
17+
)
1518
from .argparse_completer import set_default_argparse_completer
1619
from .argparse_utils import (
1720
Cmd2ArgumentParser,
@@ -88,6 +91,8 @@
8891
"Choices",
8992
"CompletionItem",
9093
"Completions",
94+
# Annotated commands
95+
"ArgumentBlock",
9196
# Decorators
9297
"with_annotated",
9398
"with_argument_list",

0 commit comments

Comments
 (0)