1111from operator import attrgetter
1212
1313import attr
14- from dataclasses import dataclass , field
1514from ruamel .yaml import yaml_object
1615from word2number import w2n
1716
2120from aclimatise .name_generation import segment_string
2221from aclimatise .nlp import wordsegment
2322from aclimatise .usage_parser .model import UsageInstance
24- from aclimatise .yaml import yaml
23+ from aclimatise .yaml import AttrYamlMixin , yaml
2524
2625
2726def first (lst : typing .List , default ):
@@ -50,13 +49,15 @@ def useless_name(name: typing.List[str]):
5049
5150
5251@yaml_object (yaml )
53- @dataclass
54- class Command :
52+ @attr .s (
53+ auto_attribs = True ,
54+ )
55+ class Command (AttrYamlMixin ):
5556 """
5657 Class representing an entire command or subcommand, e.g. `bwa mem` or `grep`
5758 """
5859
59- def __post_init__ (self ):
60+ def __attrs_post_init__ (self ):
6061 # Store certain special flags in their own fields
6162 if self .help_flag is None :
6263 for flag in self .named :
@@ -235,12 +236,12 @@ def command_tree(self) -> typing.Generator["Command", None, None]:
235236 The command line used to invoke this command, e.g. ["bwa", "mem"]
236237 """
237238
238- positional : typing .List ["Positional" ] = field ( default_factory = list )
239+ positional : typing .List ["Positional" ] = attr . ib ( factory = list )
239240 """
240241 All positional arguments supported by this command
241242 """
242243
243- named : typing .List ["Flag" ] = field ( default_factory = list )
244+ named : typing .List ["Flag" ] = attr . ib ( factory = list )
244245 """
245246 All named arguments (flags) supported by this command
246247 """
@@ -250,12 +251,12 @@ def command_tree(self) -> typing.Generator["Command", None, None]:
250251 The parent command, if this is a subcommand
251252 """
252253
253- subcommands : typing .List ["Command" ] = field ( default_factory = list )
254+ subcommands : typing .List ["Command" ] = attr . ib ( factory = list )
254255 """
255256 A list of subcommands of this command, e.g. "bwa" has the subcommand "bwa mem"
256257 """
257258
258- usage : typing .List ["UsageInstance" ] = field ( default_factory = list )
259+ usage : typing .List ["UsageInstance" ] = attr . ib ( factory = list )
259260 """
260261 Different usage examples provided by the help
261262 """
@@ -293,7 +294,7 @@ def command_tree(self) -> typing.Generator["Command", None, None]:
293294
294295@yaml_object (yaml )
295296@attr .s (auto_attribs = True )
296- class CliArgument :
297+ class CliArgument ( AttrYamlMixin ) :
297298 """
298299 A generic parent class for both named and positional CLI arguments
299300 """
@@ -428,11 +429,10 @@ class Flag(CliArgument):
428429 Describes the arguments to this flag, e.g. ``-n 1`` has a single numeric argument
429430 """
430431
431- def __post_init__ (self ):
432+ def __attrs_post_init__ (self ):
432433 if self .optional is None :
433434 # Flags are optional by default
434435 self .optional = True
435- super ().__post_init__ ()
436436
437437 @staticmethod
438438 def deduplicate (flags : typing .Collection ["Flag" ]) -> typing .List ["Flag" ]:
@@ -595,8 +595,8 @@ def shortest_synonym(self) -> str:
595595
596596
597597@yaml_object (yaml )
598- @dataclass
599- class FlagSynonym :
598+ @attr . s ( auto_attribs = True )
599+ class FlagSynonym ( AttrYamlMixin ) :
600600 """
601601 Internal class for storing the arguments for a single synonym
602602 """
@@ -679,8 +679,8 @@ def infer_type(string) -> typing.Optional[cli_types.CliType]:
679679
680680
681681@yaml_object (yaml )
682- @dataclass
683- class FlagArg (abc .ABC ):
682+ @attr . s ( auto_attribs = True )
683+ class FlagArg (abc .ABC , AttrYamlMixin ):
684684 """
685685 The data model for the argument or arguments for a flag, for example a flag might have no arguments, it might have
686686 one argument, it might accept one option from a list of options, or it might accept an arbitrary number of inputs
@@ -709,7 +709,7 @@ def num_args(self) -> int:
709709
710710
711711@yaml_object (yaml )
712- @dataclass
712+ @attr . s ( auto_attribs = True )
713713class EmptyFlagArg (FlagArg ):
714714 """
715715 A flag that has no arguments, e.g. `--quiet` that is either present or not present
@@ -723,7 +723,7 @@ def get_type(self):
723723
724724
725725@yaml_object (yaml )
726- @dataclass
726+ @attr . s ( auto_attribs = True )
727727class OptionalFlagArg (FlagArg ):
728728 """
729729 When the flag has multiple arguments, some of which are optional, e.g.
@@ -757,7 +757,7 @@ def get_type(self):
757757
758758
759759@yaml_object (yaml )
760- @dataclass
760+ @attr . s ( auto_attribs = True )
761761class SimpleFlagArg (FlagArg ):
762762 """
763763 When a flag has one single argument, e.g. `-e PATTERN`, where PATTERN is the argument
@@ -779,7 +779,7 @@ def get_type(self):
779779
780780
781781@yaml_object (yaml )
782- @dataclass
782+ @attr . s ( auto_attribs = True )
783783class RepeatFlagArg (FlagArg ):
784784 """
785785 When a flag accepts 1 or more arguments, e.g. `--samout SAMOUTS [SAMOUTS ...]`
@@ -805,7 +805,7 @@ def get_type(self):
805805
806806
807807@yaml_object (yaml )
808- @dataclass
808+ @attr . s ( auto_attribs = True )
809809class ChoiceFlagArg (FlagArg ):
810810 """
811811 When a flag accepts one option from a list of options, e.g. `-s {yes,no,reverse}`
0 commit comments