Title: Template functionality for argument blocks using `with_annotaed` decorator · Issue #1689 · python-cmd2/cmd2 · GitHub
Open Graph Title: Template functionality for argument blocks using `with_annotaed` decorator · Issue #1689 · python-cmd2/cmd2
X Title: Template functionality for argument blocks using `with_annotaed` decorator · Issue #1689 · python-cmd2/cmd2
Description: Feature Request To avoid redundant code, add a template mechanism for argument blocks that appear in multiple commands. Using the with_argparse decorator this is easy by reusing a function that modifies a parser; with_annotated currently...
Open Graph Description: Feature Request To avoid redundant code, add a template mechanism for argument blocks that appear in multiple commands. Using the with_argparse decorator this is easy by reusing a function that mod...
X Description: Feature Request To avoid redundant code, add a template mechanism for argument blocks that appear in multiple commands. Using the with_argparse decorator this is easy by reusing a function that mod...
Opengraph URL: https://github.com/python-cmd2/cmd2/issues/1689
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Template functionality for argument blocks using `with_annotaed` decorator","articleBody":"# Feature Request\n\nTo avoid redundant code, add a template mechanism for argument blocks that appear in multiple commands. Using the `with_argparse` decorator this is easy by reusing a function that modifies a parser; `with_annotated` currently has no simple equivalent.\n\n## Possible solutions\n\n- Use a TypedDict + Unpack to reuse a named block of annotations:\n```python\nclass ArgumentBlock(TypedDict):\n # define reusable keys/values here\n ...\n\nclass App(Cmd):\n\n @with_annotated\n def do_a(..., **kwargs: Unpack[ArgumentBlock]) -\u003e None:\n ...\n\n @with_annotated\n def do_b(..., **kwargs: Unpack[ArgumentBlock]) -\u003e None:\n ...\n```\n\n- Allow attaching a predefined parser to the parser generated by `with_annotated`, and expose the resulting namespace inside the decorated method for easy access.\n\nBoth approaches reduce duplication; the second may be simpler to implement.","author":{"url":"https://github.com/neoniobium","@type":"Person","name":"neoniobium"},"datePublished":"2026-06-10T14:53:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/1689/cmd2/issues/1689"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:28ed4672-1e63-1d03-4a2b-e82717636f3d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C246:14FBB8:38B361:4D2C44:6A4D9F17 |
| html-safe-nonce | 26a9268b6803bc1e3a02af55f13eba2a62dd98cc1c657f888b245901bea71389 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjQ2OjE0RkJCODozOEIzNjE6NEQyQzQ0OjZBNEQ5RjE3IiwidmlzaXRvcl9pZCI6IjU0Mzc1MTYxMjEzNjMwMjk3ODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e5c76cafa741effe9c523868fa8346687862438b7b33076b5d617c6c2eec7acf |
| hovercard-subject-tag | issue:4632378618 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-cmd2/cmd2/1689/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0aa88cc11c4effc352581a0535ff6eb66bf39e3b2eac7911a3cf980e36716e09/python-cmd2/cmd2/issues/1689 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0aa88cc11c4effc352581a0535ff6eb66bf39e3b2eac7911a3cf980e36716e09/python-cmd2/cmd2/issues/1689 |
| og:image:alt | Feature Request To avoid redundant code, add a template mechanism for argument blocks that appear in multiple commands. Using the with_argparse decorator this is easy by reusing a function that mod... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | neoniobium |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-cmd2/cmd2 git https://github.com/python-cmd2/cmd2.git |
| octolytics-dimension-user_id | 17161025 |
| octolytics-dimension-user_login | python-cmd2 |
| octolytics-dimension-repository_id | 51442999 |
| octolytics-dimension-repository_nwo | python-cmd2/cmd2 |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 51442999 |
| octolytics-dimension-repository_network_root_nwo | python-cmd2/cmd2 |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7f13faa65cccc9b729d674da83335d5dcfdfd193 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width