Package: argklass
Inspired bySimple Parsing, simplified
and extended to build extensive, extendable command line interface without much code.pipinstallargklassFeaturesAutomatic cli discovery and command plugin# Folder structureproject/cli/├──__init__.py<=empty├──editor/│├──__init__.py<=ParentCommand(editor)│├──cook.py<=Command(cook)│├──client.py<=Command(client)│├──game.py<=Command(game)│└──open.py<=Command(open)└──uat/├──__init__.py<=ParentCommand(uat)├──localize.py<=Command(localize)└──test.py<=Command(test)#  editor/__init__.pyfromargklass.commandimportParentCommandclassEditor(ParentCommand):name="editor"COMMANDS=Editor# cook.pyfromargklass.commandimportCommandclassCook(Command):name="cook"@staticmethoddefexecute(args)->int:print("cook")COMMANDS=Cook#cli=CommandLineInterface(project.cli)cli.run()# orcli.run(["editor","cook","--help"])#clieditorcook--helpcliuatlocalize--helpNew Argument formatable to show the entire command line interface with all its subparsersnew format mirror dataclass syntaxeditor                                           Set of commands to launch the editors in different modes
   server                                       Parameters added to the Map URL
   game                                         docstring ...
   client                                       docstring ...
   resavepackages                               docstring ...
   cook                                         docstring ...
   ml                                           Launch unreal engine with mladapter setup
   editor                                       Other arguments
   open                                         docstring ...
   localize                                     docstring ...
   worldpartition                               Convert a UE4 map using world partition
   -h, --help                                   Show help
engine                                           Set of commands to manage engine installation/source
      add                                          docstring ...
      update                                       Update the engine source code
format                                             docstring ...
      --profile: str                               docstring ...
      --file: str                                  docstring ...
      --fail_on_error: bool = False                docstring ...
      --col: int = 24                              docstring ...Compact argparse definitiondefworkdir():d=os.getcwd()ifos.access(d,os.W_OK):returndreturnNone@dataclassclassMyArguments:a:str# Positionalb:int=20# My argumentc:bool=False# My argumentd:int=choice(0,1,2,3,4,default=1)# choicese:List[int]=argument(default=[0])# listf:Optional[int]=None# Optionalp:Tuple[int,int]=(1,1)# help pg:Color=Color.RED# help gs:SubArgs=SubArgs# helps groupcmd:Union[cmd1,cmd2]=subparsers(cmd1=cmd1,cmd2=cmd2)# Command subparserde:str=deduceable(workdir)parser=ArgumentParser()parser.add_arguments(MyArguments)args=parser.parse_args()Save and load arguments from configuration filesparser=build_parser(commands)# load/save defaults before parsingsave_defaults(parser,"config.hjson")apply_defaults(parser,"config.hjson")args=parser.parse_args(["editor","editor"])# load save arguments after parsingsave_as_config(parser,args,"dump.hjson")apply_config(parser,args,"dump.hjson")Lower level interface, that gives you back all of argparse power@dataclassclassSubArgs:aa:str=argument(default="123")@dataclassclasscmd1:args:str="str1"@dataclassclasscmd2:args:str="str2"@dataclassclassMyArguments:a:str=argument(help="Positional")b:int=argument(default=20,help="My argument")c:bool=argument(action="store_true",help="My argument")d:int=argument(default=1,choices=[0,1,2,3,4],help="choices")e:List[int]=argument(default=[0],help="list")f:Optional[int]=argument(default=None,help="Optional")p:Tuple[int,int]=argument(default=(1,1),help="help p")g:Color=argument(default=Color.RED,help="help g")s:SubArgs=group(default=SubArgs,help="helps group")cmd:Union[cmd1,cmd2]=subparsers(cmd1=cmd1,cmd2=cmd2)parser=ArgumentParser()parser.add_arguments(MyArguments)args=parser.parse_args()Architectureargklass works by building the argument parser as a tree, adding
metadata to each nodes when necessary.One of the core component isArgumentParserIteratorwhich traverse the parsing tree.
Each features, such as argument grouping into dataclasses or saving/loading configuration,
are implemented as a simple traversal.This enable us to implement each feature independently from each other and make them optional.