From f980fbe17bf670d8cdc82c03f9769489061c7694 Mon Sep 17 00:00:00 2001 From: Daniel Harrison <13085330+harro@users.noreply.github.com> Date: Mon, 9 Nov 2026 01:29:26 +0000 Subject: [PATCH 1/2] Fix typos. --- tcli/command_parser.py | 2 +- tcli/command_parser_test.py | 2 +- tcli/command_response_test.py | 2 +- tcli/inventory_base.py | 4 ++-- tcli/tcli_lib.py | 2 +- tcli/tcli_test.py | 10 +++++----- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tcli/command_parser.py b/tcli/command_parser.py index 350e0cc..047cd45 100644 --- a/tcli/command_parser.py +++ b/tcli/command_parser.py @@ -394,7 +394,7 @@ def ParseCommandLine(self, line: str) -> tuple[str, list[str], bool]: if not line: raise ParseError('Missing escape command.') - # Expand command into command name, args and it it is append or not. + # Expand command into command name, args and if it is append or not. command_name, line, append = self._CommandExpand(line) if command_name not in self: diff --git a/tcli/command_parser_test.py b/tcli/command_parser_test.py index 59abe1c..ed24814 100644 --- a/tcli/command_parser_test.py +++ b/tcli/command_parser_test.py @@ -335,7 +335,7 @@ def testParseCommandLine1(self): 'hoo the line is too long', ) - # Commnad with raw argument. + # Command with raw argument. self.cmd_parser.RegisterCommand( 'foo', 'A help string.', short_name='F', raw_arg=True ) diff --git a/tcli/command_response_test.py b/tcli/command_response_test.py index 0456830..660ea7a 100644 --- a/tcli/command_response_test.py +++ b/tcli/command_response_test.py @@ -155,7 +155,7 @@ def testGetRow(self): self.cmd_response.InitCommandRow(1, 'testing') # Two devices, so two responses for each of the two rows. - # Hence four requet IDs: 1-4. + # Hence four request IDs: 1-4. self.cmd_response.SetRequest(1, 1) self.cmd_response.SetRequest(1, 2) # Responses for the first command have the higher IDs ... just because. diff --git a/tcli/inventory_base.py b/tcli/inventory_base.py index 72b299d..6e0542d 100644 --- a/tcli/inventory_base.py +++ b/tcli/inventory_base.py @@ -37,7 +37,7 @@ # Global vars so flags.FLAGS has inventroy intelligence in the main program. # Maximum number of devices that can be the recipient of a command. -# Can (and should) be overriden in the child module or the command line. +# Can (and should) be overridden in the child module or the command line. DEFAULT_MAXTARGETS = 50 # System default for what device targets to exclude from matching. # Set this to avoid overly matching on devices that may rarely be an @@ -741,7 +741,7 @@ def _BuildDeviceList(self) -> list[str]: return self._device_list def _AsyncLoad(self) -> None: - """Wrapper for calling FetchDevices from withing a thread.""" + """Wrapper for calling FetchDevices from within a thread.""" try: self._FetchDevices() diff --git a/tcli/tcli_lib.py b/tcli/tcli_lib.py index 171eff2..1effab5 100644 --- a/tcli/tcli_lib.py +++ b/tcli/tcli_lib.py @@ -203,7 +203,7 @@ def __init__( self.inventory.RegisterCommands(self.cli_parser) command_register.RegisterCommands(self, self.cli_parser) command_register.SetFlagDefaults(self.cli_parser) - # If interactive then the user will input furhter commands. + # If interactive then the user will input further commands. # So we enable safe mode and apply the users .tclirc file. if self.interactive: # Set safe mode. diff --git a/tcli/tcli_test.py b/tcli/tcli_test.py index 91979ef..8beb223 100644 --- a/tcli/tcli_test.py +++ b/tcli/tcli_test.py @@ -182,10 +182,10 @@ def testCallback(self): self.tcli_obj._FormatRow = mock.Mock() - # self.tcli_obj.Callback( - # inventory.Response(99, "device_name", "command", "data", "error")) - # # Test that nonexistant uid trigger early return. - # self.assertFalse(self.tcli_obj.cmd_response._response_count) + self.tcli_obj._Callback( + inventory.Response(99, "device_name", "command", "data", "error")) + # Test that nonexistent uid triggers an early return. + self.assertFalse(self.tcli_obj.cmd_response._response_count) self.tcli_obj.cmd_response.InitCommandRow(0, '') self.tcli_obj.cmd_response.InitCommandRow(1, '') @@ -747,7 +747,7 @@ def testTCLIFilter(self): "Invalid filter 'not_a_valid_filter'.", msgtype='warning' ) - def testTCLIBufferAsignment(self): + def testTCLIBufferAssignment(self): # Ensure logging is clear self.tcli_obj.record = '' From b476904a4bdac12b8904941874f33a0ab900c91b Mon Sep 17 00:00:00 2001 From: Daniel Harrison <13085330+harro@users.noreply.github.com> Date: Mon, 9 Nov 2026 06:53:59 +0000 Subject: [PATCH 2/2] Support inventory.CreateCmdRequest (Factory Method). --- tcli/tcli_lib.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tcli/tcli_lib.py b/tcli/tcli_lib.py index 1effab5..e0bbda2 100644 --- a/tcli/tcli_lib.py +++ b/tcli/tcli_lib.py @@ -123,6 +123,7 @@ short_name='t', ) + class Error(Exception): """Base class for errors.""" @@ -215,10 +216,7 @@ def __init__( def __copy__(self) -> 'TCLI': """Copies attributes from self to new tcli object.""" - inv_copy = ( - copy.copy(self.inventory) - if self.inventory is not None else None - ) + inv_copy = copy.copy(self.inventory) if self.inventory is not None else None # Create new instance with existing inventory. tcli_obj = type(self)(inv=inv_copy) # TODO: Why does this break ParseCommands? @@ -369,7 +367,14 @@ def _CmdRequests( # Create command requests. for device in device_list: - req = inventory.CmdRequest(device, command, self.mode) + # Site specific factory method for creating CmdRequest. + # Required if the CmdRequest needs device specific details. + if isinstance(self.inventory, inventory.Inventory) and hasattr( + self.inventory, 'CreateCmdRequest' + ): + req = self.inventory.CreateCmdRequest(device, command, self.mode) + else: + req = inventory.CmdRequest(device, command, self.mode) # Track the order that commands are submitted. # Responses are received in any order and # we use the row ID to reassemble.