From c5f8a914774bca5a0fa2f11df4cca6a904069d52 Mon Sep 17 00:00:00 2001 From: Bridget Date: Mon, 13 Apr 2020 19:15:01 +0200 Subject: [PATCH] Remove endpoint commands on disconnect --- lslsh.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lslsh.py b/lslsh.py index 5fa20de..10262d5 100755 --- a/lslsh.py +++ b/lslsh.py @@ -107,6 +107,8 @@ class Shell(cmd.Cmd): print("Disconnected from remote (without acknowledgement).") self.url = None + for cmd in self.remote_commands: + self.remove_cmd(cmd) else: print("Error: Not connected to remote.") @@ -122,6 +124,13 @@ class Shell(cmd.Cmd): setattr(self, f"do_{name}", do_cmd) self.remote_commands.append(name) + def remove_cmd(self, name): + """Remove a command from the shell.""" + + if not hasattr(Shell, f"do_{name}") and hasattr(self, f"do_{name}"): + delattr(self, f"do_{name}") + filter(lambda a: a != name, self.remote_commands) + def do_help(self, arg): """List available commands with "help" or detailed help with "help cmd".""" if arg: