Skip to content

Commit

Permalink
Rename CommandSet.__private_cmd to CommandSet.__cmd_internal.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Nov 5, 2024
1 parent b93dcd9 commit e281a40
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions cmd2/command_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,27 @@ def __init__(self) -> None:
# Private reference to the CLI instance in which this CommandSet running.
# This will be set when the CommandSet is registered and it should be
# accessed by child classes using the self._cmd property.
self.__private_cmd: Optional[cmd2.Cmd] = None
self.__cmd_internal: Optional[cmd2.Cmd] = None

self._settables: Dict[str, Settable] = {}
self._settable_prefix = self.__class__.__name__

@property
def _cmd(self) -> 'cmd2.Cmd':
"""
Property for child classes to access self.__private_cmd.
Property for child classes to access self.__cmd_internal.
Using this property ensures that self.__private_cmd has been set
Using this property ensures that self.__cmd_internal has been set
and it tells type checkers that it's no longer a None type.
Override this property if you need to change its return type to a
child class of Cmd.
:raises: CommandSetRegistrationError if CommandSet is not registered.
"""
if self.__private_cmd is None:
if self.__cmd_internal is None:
raise CommandSetRegistrationError('This CommandSet is not registered')
return self.__private_cmd
return self.__cmd_internal

def on_register(self, cmd: 'cmd2.Cmd') -> None:
"""
Expand All @@ -126,8 +126,8 @@ def on_register(self, cmd: 'cmd2.Cmd') -> None:
:param cmd: The cmd2 main application
:raises: CommandSetRegistrationError if CommandSet is already registered.
"""
if self.__private_cmd is None:
self.__private_cmd = cmd
if self.__cmd_internal is None:
self.__cmd_internal = cmd
else:
raise CommandSetRegistrationError('This CommandSet has already been registered')

Expand All @@ -151,7 +151,7 @@ def on_unregistered(self) -> None:
Called by ``cmd2.Cmd`` after a CommandSet has been unregistered and all its commands removed from the CLI.
Subclasses can override this to perform remaining cleanup steps.
"""
self.__private_cmd = None
self.__cmd_internal = None

@property
def settable_prefix(self) -> str:
Expand All @@ -167,7 +167,7 @@ def add_settable(self, settable: Settable) -> None:
:param settable: Settable object being added
"""
if self.__private_cmd is not None:
if self.__cmd_internal is not None:
if not self._cmd.always_prefix_settables:
if settable.name in self._cmd.settables.keys() and settable.name not in self._settables.keys():
raise KeyError(f'Duplicate settable: {settable.name}')
Expand Down

0 comments on commit e281a40

Please sign in to comment.