@@ -42,6 +42,9 @@ class LogLevel(str, Enum):
4242 error = "error"
4343
4444
45+ ANNOTATED_CATEGORY = "Annotated Commands"
46+
47+
4548class AnnotatedExample (Cmd ):
4649 """Demonstrates @with_annotated strengths over @with_argparser."""
4750
@@ -57,6 +60,7 @@ def __init__(self) -> None:
5760 # Here the decorator infers everything from the annotations.
5861
5962 @cmd2 .with_annotated
63+ @cmd2 .with_category (ANNOTATED_CATEGORY )
6064 def do_add (self , a : int , b : int = 0 , verbose : bool = False ) -> None :
6165 """Add two integers. Types are inferred from annotations.
6266
@@ -75,6 +79,7 @@ def do_add(self, a: int, b: int = 0, verbose: bool = False) -> None:
7579 # Here the Enum type provides choices and validation automatically.
7680
7781 @cmd2 .with_annotated
82+ @cmd2 .with_category (ANNOTATED_CATEGORY )
7883 def do_paint (
7984 self ,
8085 item : str ,
@@ -94,6 +99,7 @@ def do_paint(
9499 # Here the Path type triggers filesystem completion automatically.
95100
96101 @cmd2 .with_annotated
102+ @cmd2 .with_category (ANNOTATED_CATEGORY )
97103 def do_copy (self , src : Path , dst : Path ) -> None :
98104 """Copy a file. Path parameters auto-complete filesystem paths.
99105
@@ -109,6 +115,7 @@ def do_copy(self, src: Path, dst: Path) -> None:
109115 # True default -> --no-flag (store_false)
110116
111117 @cmd2 .with_annotated
118+ @cmd2 .with_category (ANNOTATED_CATEGORY )
112119 def do_build (
113120 self ,
114121 target : str ,
@@ -135,6 +142,7 @@ def do_build(
135142 # Here list[float] does both at once.
136143
137144 @cmd2 .with_annotated
145+ @cmd2 .with_category (ANNOTATED_CATEGORY )
138146 def do_sum (self , numbers : list [float ]) -> None :
139147 """Sum numbers. ``list[T]`` becomes ``nargs='+'`` automatically.
140148
@@ -148,6 +156,7 @@ def do_sum(self, numbers: list[float]) -> None:
148156 # Here each parameter is a typed local variable.
149157
150158 @cmd2 .with_annotated
159+ @cmd2 .with_category (ANNOTATED_CATEGORY )
151160 def do_greet (self , name : str , count : int = 1 , loud : bool = False ) -> None :
152161 """Greet someone. Parameters are typed -- no Namespace unpacking.
153162
@@ -175,6 +184,7 @@ def context_choices(self, arg_tokens: dict[str, list[str]]) -> Choices:
175184 return Choices .from_values (["play" ])
176185
177186 @cmd2 .with_annotated
187+ @cmd2 .with_category (ANNOTATED_CATEGORY )
178188 def do_score (
179189 self ,
180190 sport : Annotated [
@@ -205,6 +215,7 @@ def do_score(
205215 # -- Preserve quotes -----------------------------------------------------
206216
207217 @cmd2 .with_annotated (preserve_quotes = True )
218+ @cmd2 .with_category (ANNOTATED_CATEGORY )
208219 def do_echo (self , text : str ) -> None :
209220 """Echo text with quotes preserved.
210221
0 commit comments