1- from functools import cached_property , reduce
1+ from functools import reduce
22from operator import add
33from typing import Annotated , NewType , OrderedDict
44
99from cmdcomp .v1 .command .option import V1OptionType , V1SpecificOptions , V1StrOption
1010from cmdcomp .v1 .command .option .command_option import V1CommandOption
1111from cmdcomp .v1 .command .option .file_option import V1FileOption
12+ from cmdcomp .v2 .mixin .has_alias import HasAlias
1213
1314V1SubcommandName = NewType ("V1SubcommandName" , str )
1415
1819V1Completions = V1Candidates | dict [str , "V1Completions" ] # type: ignore
1920
2021
21- class V1SubCommandsCommand (Model ):
22+ class V1SubCommandsCommand (HasAlias , Model ):
2223 """A command that can specify a subcommand."""
2324
2425 model_config = ConfigDict (arbitrary_types_allowed = True )
2526
2627 alias : Annotated [
27- str | list [str ],
28+ str | list [str ] | None ,
2829 Field (
2930 title = "alias of the command." ,
30- default_factory = list ,
31+ default = None ,
3132 ),
3233 ]
3334
@@ -44,24 +45,17 @@ class V1SubCommandsCommand(Model):
4445 default_factory = OrderedDict ,
4546 )
4647
47- @cached_property
48- def aliases (self ) -> list [str ]:
49- if isinstance (self .alias , str ):
50- return [self .alias ]
51- else :
52- return self .alias
53-
5448
55- class V1SpecificOptionsCommand (Model ):
49+ class V1SpecificOptionsCommand (HasAlias , Model ):
5650 """A command that can specify options."""
5751
5852 model_config = ConfigDict (arbitrary_types_allowed = True )
5953
6054 alias : Annotated [
61- str | list [str ],
55+ str | list [str ] | None ,
6256 Field (
6357 title = "alias of the command." ,
64- default_factory = list ,
58+ default = None ,
6559 ),
6660 ]
6761
@@ -72,13 +66,6 @@ class V1SpecificOptionsCommand(Model):
7266 ),
7367 ]
7468
75- @cached_property
76- def aliases (self ) -> list [str ]:
77- if isinstance (self .alias , str ):
78- return [self .alias ]
79- else :
80- return self .alias
81-
8269
8370V1Command = V1SubCommandsCommand | V1SpecificOptionsCommand
8471
0 commit comments