diff --git a/neo/Prompt/CommandBase.py b/neo/Prompt/CommandBase.py index d9b01b092..b4dbce1c3 100644 --- a/neo/Prompt/CommandBase.py +++ b/neo/Prompt/CommandBase.py @@ -69,15 +69,20 @@ def command_desc(self): def execute_sub_command(self, id, arguments): self.__sub_commands[id].execute(arguments) - # ids: can be either a string or a list of strings. - def register_sub_command(self, ids, sub_command): - if isinstance(ids, list): - for id in ids: - self.__register_sub_command(id, sub_command) - else: - self.__register_sub_command(ids, sub_command) + def register_sub_command(self, sub_command, additional_ids=[]): + """ + Register a command as a subcommand. + It will have it's CommandDesc.command string used as id. Additional ids can be provided. + + Args: + sub_command (CommandBase): Subcommand to register. + additional_ids (List[str]): List of additional ids. Can be empty. + """ + self.__register_sub_command(sub_command, sub_command.command_desc().command) + for id in additional_ids: + self.__register_sub_command(sub_command, id) - def __register_sub_command(self, id, sub_command): + def __register_sub_command(self, sub_command, id): if id in self.__sub_commands: raise ValueError(f"{id} is already a subcommand of {self.command_desc().command}.") if sub_command.__parent_command and sub_command.__parent_command != self: diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index bd3ee75ec..788a5163e 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -29,10 +29,10 @@ class CommandWallet(CommandBase): def __init__(self): super().__init__() - self.register_sub_command('create', CommandWalletCreate()) - self.register_sub_command(['v', '--v', 'verbose'], CommandWalletVerbose()) - self.register_sub_command('migrate', CommandWalletMigrate()) - self.register_sub_command('create_addr', CommandWalletCreateAddress()) + self.register_sub_command(CommandWalletCreate()) + self.register_sub_command(CommandWalletVerbose(), ['v', '--v']) + self.register_sub_command(CommandWalletMigrate()) + self.register_sub_command(CommandWalletCreateAddress()) def command_desc(self): return CommandDesc('wallet', 'manage wallets') @@ -65,8 +65,7 @@ class CommandWalletCreate(CommandBase): def __init__(self): super().__init__() - @classmethod - def execute(cls, arguments): + def execute(self, arguments): path = get_arg(arguments, 0) if path: @@ -105,7 +104,6 @@ def execute(cls, arguments): else: print("Please specify a path") - @classmethod def command_desc(self): p1 = ParameterDesc('path', 'path to store the wallet file') return CommandDesc('create', 'creates a new NEO wallet address', [p1])