@@ -66,18 +66,25 @@ def command_desc(self):
6666 pass
6767
6868 # Raise KeyError exception if the command does not exist
69- def execute_sub_command (self , id , arguments ):
70- self .__sub_commands [id ].execute (arguments )
71-
72- # ids: can be either a string or a list of strings.
73- def register_sub_command (self , ids , sub_command ):
74- if isinstance (ids , list ):
75- for id in ids :
76- self .__register_sub_command (id , sub_command )
69+ def execute_sub_command (self , id , arguments = None ):
70+ if arguments is not None :
71+ self .__sub_commands [id ].execute (arguments )
7772 else :
78- self .__register_sub_command ( ids , sub_command )
73+ self .__sub_commands [ id ]. execute ( )
7974
80- def __register_sub_command (self , id , sub_command ):
75+ def register_sub_command (self , sub_command , additional_ids = []):
76+ """
77+ Register a command as a subcommand.
78+ It will have it's CommandDesc.command string used as id. Additional ids can be provided.
79+ Args:
80+ sub_command (CommandBase): Subcommand to register.
81+ additional_ids (List[str]): List of additional ids. Can be empty.
82+ """
83+ self .__register_sub_command (sub_command , sub_command .command_desc ().command )
84+ for id in additional_ids :
85+ self .__register_sub_command (sub_command , id )
86+
87+ def __register_sub_command (self , sub_command , id ):
8188 if id in self .__sub_commands :
8289 raise ValueError (f"{ id } is already a subcommand of { self .command_desc ().command } ." )
8390 if sub_command .__parent_command and sub_command .__parent_command != self :
0 commit comments