mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-01-23 05:41:13 -05:00
panctl: Add a help command.
This commit is contained in:
parent
1faa787090
commit
cc76a8159b
@ -51,11 +51,15 @@ class PanctlArgParse(argparse.ArgumentParser):
|
|||||||
|
|
||||||
|
|
||||||
class PanctlParser():
|
class PanctlParser():
|
||||||
def __init__(self):
|
def __init__(self, commands):
|
||||||
|
self.commands = commands
|
||||||
self.parser = PanctlArgParse()
|
self.parser = PanctlArgParse()
|
||||||
subparsers = self.parser.add_subparsers(dest="subcommand")
|
subparsers = self.parser.add_subparsers(dest="subcommand")
|
||||||
subparsers.add_parser("list-servers")
|
subparsers.add_parser("list-servers")
|
||||||
|
|
||||||
|
help = subparsers.add_parser("help")
|
||||||
|
help.add_argument("command", choices=self.commands)
|
||||||
|
|
||||||
list_devices = subparsers.add_parser("list-devices")
|
list_devices = subparsers.add_parser("list-devices")
|
||||||
list_devices.add_argument("pan_user", type=str)
|
list_devices.add_argument("pan_user", type=str)
|
||||||
list_devices.add_argument("user_id", type=str)
|
list_devices.add_argument("user_id", type=str)
|
||||||
@ -277,6 +281,12 @@ class PanCompleter(Completer):
|
|||||||
elif command == "list-devices":
|
elif command == "list-devices":
|
||||||
return self.complete_list_devices(last_word, words)
|
return self.complete_list_devices(last_word, words)
|
||||||
|
|
||||||
|
elif command == "help":
|
||||||
|
if len(words) == 2:
|
||||||
|
return self.complete_commands(last_word)
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
@ -317,7 +327,43 @@ class PanCtl:
|
|||||||
ctl = attr.ib(init=False)
|
ctl = attr.ib(init=False)
|
||||||
devices = attr.ib(init=False)
|
devices = attr.ib(init=False)
|
||||||
|
|
||||||
|
command_help = {
|
||||||
|
"help": "Display help about commands.",
|
||||||
|
"list-servers": ("List the configured homeservers and pan users on "
|
||||||
|
"each homeserver."),
|
||||||
|
"list-devices": ("List the devices of a user that are known to the "
|
||||||
|
"pan-user."),
|
||||||
|
"start-verification": ("Start an interactive key verification between "
|
||||||
|
"the given pan-user and user."),
|
||||||
|
"accept-verification": ("Accept an interactive key verification that "
|
||||||
|
"the given user has started with our given "
|
||||||
|
"pan-user."),
|
||||||
|
"cancel-verification": ("Cancel an interactive key verification "
|
||||||
|
"between the given pan-user and user."),
|
||||||
|
"confirm-verification": ("Confirm that the short authentication "
|
||||||
|
"string of the interactive key verification "
|
||||||
|
"with the given pan-user and user is "
|
||||||
|
"matching."),
|
||||||
|
"verify-device": ("Manually mark the given device as verified."),
|
||||||
|
"unverify-device": ("Mark a previously verified device of the given "
|
||||||
|
"user as unverified."),
|
||||||
|
"blacklist-device": ("Manually mark the given device of the given "
|
||||||
|
"user as blacklisted."),
|
||||||
|
"unblacklist-device": ("Mark a previously blacklisted device of the "
|
||||||
|
"given user as unblacklisted."),
|
||||||
|
"send-anyways": ("Send a room message despite having unverified "
|
||||||
|
"devices in the room and mark the devices as "
|
||||||
|
"ignored."),
|
||||||
|
"cancel-sending": ("Cancel the send of a room message in a room that "
|
||||||
|
"contains unverified devices"),
|
||||||
|
"import-keys": ("Import end-to-end encryption keys from the given "
|
||||||
|
"file for the given pan-user."),
|
||||||
|
"export-keys": ("Export end-to-end encryption keys to the given file "
|
||||||
|
"for the given pan-user."),
|
||||||
|
}
|
||||||
|
|
||||||
commands = [
|
commands = [
|
||||||
|
"help",
|
||||||
"list-servers",
|
"list-servers",
|
||||||
"list-devices",
|
"list-devices",
|
||||||
"export-keys",
|
"export-keys",
|
||||||
@ -352,6 +398,9 @@ class PanCtl:
|
|||||||
self.devices.VerificationString.connect(self.show_sas)
|
self.devices.VerificationString.connect(self.show_sas)
|
||||||
self.devices.VerificationDone.connect(self.sas_done)
|
self.devices.VerificationDone.connect(self.sas_done)
|
||||||
|
|
||||||
|
def show_help(self, command):
|
||||||
|
print(self.command_help[command])
|
||||||
|
|
||||||
def unverified_devices(self, pan_user, room_id, display_name):
|
def unverified_devices(self, pan_user, room_id, display_name):
|
||||||
self.completer.rooms[pan_user].add(room_id)
|
self.completer.rooms[pan_user].add(room_id)
|
||||||
print(f"Error sending message for user {pan_user}, "
|
print(f"Error sending message for user {pan_user}, "
|
||||||
@ -492,7 +541,7 @@ class PanCtl:
|
|||||||
if not result:
|
if not result:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
parser = PanctlParser()
|
parser = PanctlParser(self.commands)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args(result.split())
|
args = parser.parse_args(result.split())
|
||||||
@ -504,6 +553,9 @@ class PanCtl:
|
|||||||
if command == "list-servers":
|
if command == "list-servers":
|
||||||
self.list_servers()
|
self.list_servers()
|
||||||
|
|
||||||
|
if command == "help":
|
||||||
|
self.show_help(args.command)
|
||||||
|
|
||||||
elif command == "import-keys":
|
elif command == "import-keys":
|
||||||
self.own_message_ids.append(
|
self.own_message_ids.append(
|
||||||
self.ctl.ImportKeys(
|
self.ctl.ImportKeys(
|
||||||
|
Loading…
Reference in New Issue
Block a user