45
45
from . import ansi , constants , plugin , utils
46
46
from .argparse_custom import DEFAULT_ARGUMENT_PARSER , CompletionItem
47
47
from .clipboard import can_clip , get_paste_buffer , write_to_paste_buffer
48
- from .command_definition import CommandSet , _partial_passthru
48
+ from .command_definition import CommandSet
49
49
from .constants import COMMAND_FUNC_PREFIX , COMPLETER_FUNC_PREFIX , HELP_FUNC_PREFIX
50
50
from .decorators import with_argparser , as_subcommand_to
51
51
from .exceptions import (
@@ -186,7 +186,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
186
186
:param auto_load_commands: If True, cmd2 will check for all subclasses of `CommandSet`
187
187
that are currently loaded by Python and automatically
188
188
instantiate and register all commands. If False, CommandSets
189
- must be manually installed with `install_command_set `.
189
+ must be manually installed with `register_command_set `.
190
190
"""
191
191
# If use_ipython is False, make sure the ipy command isn't available in this instance
192
192
if not use_ipython :
@@ -264,7 +264,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
264
264
self ._cmd_to_command_sets = {} # type: Dict[str, CommandSet]
265
265
if command_sets :
266
266
for command_set in command_sets :
267
- self .install_command_set (command_set )
267
+ self .register_command_set (command_set )
268
268
269
269
if auto_load_commands :
270
270
self ._autoload_commands ()
@@ -452,11 +452,11 @@ def load_commandset_by_type(commandset_types: List[Type]) -> None:
452
452
or len (init_sig .parameters ) != 1
453
453
or 'self' not in init_sig .parameters ):
454
454
cmdset = cmdset_type ()
455
- self .install_command_set (cmdset )
455
+ self .register_command_set (cmdset )
456
456
457
457
load_commandset_by_type (all_commandset_defs )
458
458
459
- def install_command_set (self , cmdset : CommandSet ) -> None :
459
+ def register_command_set (self , cmdset : CommandSet ) -> None :
460
460
"""
461
461
Installs a CommandSet, loading all commands defined in the CommandSet
462
462
@@ -476,23 +476,20 @@ def install_command_set(self, cmdset: CommandSet) -> None:
476
476
try :
477
477
for method_name , method in methods :
478
478
command = method_name [len (COMMAND_FUNC_PREFIX ):]
479
- command_wrapper = _partial_passthru (method , self )
480
479
481
- self ._install_command_function (command , command_wrapper , type (cmdset ).__name__ )
480
+ self ._install_command_function (command , method , type (cmdset ).__name__ )
482
481
installed_attributes .append (method_name )
483
482
484
483
completer_func_name = COMPLETER_FUNC_PREFIX + command
485
484
cmd_completer = getattr (cmdset , completer_func_name , None )
486
485
if cmd_completer is not None :
487
- completer_wrapper = _partial_passthru (cmd_completer , self )
488
- self ._install_completer_function (command , completer_wrapper )
486
+ self ._install_completer_function (command , cmd_completer )
489
487
installed_attributes .append (completer_func_name )
490
488
491
489
help_func_name = HELP_FUNC_PREFIX + command
492
490
cmd_help = getattr (cmdset , help_func_name , None )
493
491
if cmd_help is not None :
494
- help_wrapper = _partial_passthru (cmd_help , self )
495
- self ._install_help_function (command , help_wrapper )
492
+ self ._install_help_function (command , cmd_help )
496
493
installed_attributes .append (help_func_name )
497
494
498
495
self ._cmd_to_command_sets [command ] = cmdset
@@ -508,7 +505,7 @@ def install_command_set(self, cmdset: CommandSet) -> None:
508
505
if cmdset in self ._cmd_to_command_sets .values ():
509
506
self ._cmd_to_command_sets = \
510
507
{key : val for key , val in self ._cmd_to_command_sets .items () if val is not cmdset }
511
- cmdset .on_unregister (self )
508
+ cmdset .on_unregister ()
512
509
raise
513
510
514
511
def _install_command_function (self , command : str , command_wrapper : Callable , context = '' ):
@@ -549,7 +546,7 @@ def _install_help_function(self, cmd_name: str, cmd_help: Callable):
549
546
raise CommandSetRegistrationError ('Attribute already exists: {}' .format (help_func_name ))
550
547
setattr (self , help_func_name , cmd_help )
551
548
552
- def uninstall_command_set (self , cmdset : CommandSet ):
549
+ def unregister_command_set (self , cmdset : CommandSet ):
553
550
"""
554
551
Uninstalls a CommandSet and unloads all associated commands
555
552
:param cmdset: CommandSet to uninstall
@@ -581,7 +578,7 @@ def uninstall_command_set(self, cmdset: CommandSet):
581
578
if hasattr (self , HELP_FUNC_PREFIX + cmd_name ):
582
579
delattr (self , HELP_FUNC_PREFIX + cmd_name )
583
580
584
- cmdset .on_unregister (self )
581
+ cmdset .on_unregister ()
585
582
self ._installed_command_sets .remove (cmdset )
586
583
587
584
def _check_uninstallable (self , cmdset : CommandSet ):
@@ -656,11 +653,7 @@ def _register_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
656
653
raise CommandSetRegistrationError ('Could not find argparser for command "{}" needed by subcommand: {}'
657
654
.format (command_name , str (method )))
658
655
659
- if isinstance (cmdset , CommandSet ):
660
- command_handler = _partial_passthru (method , self )
661
- else :
662
- command_handler = method
663
- subcmd_parser .set_defaults (cmd2_handler = command_handler )
656
+ subcmd_parser .set_defaults (cmd2_handler = method )
664
657
665
658
def find_subcommand (action : argparse .ArgumentParser , subcmd_names : List [str ]) -> argparse .ArgumentParser :
666
659
if not subcmd_names :
0 commit comments