# HG changeset patch # User Goffi # Date 1727359921 -7200 # Node ID 472a938a46e3bb053b369d389c03eb2c20b22d77 # Parent 6a0155f410bd421539449dc2b92396a9f7a48291 cli (message/send): add arguments for message addressing: commands have been added to add `to`, `cc` and `bcc` metadata for sending copy of the message to several entities. Metadata such as `reply-to` `reply-room` and `no-reply` are also supported. rel 450 diff -r 6a0155f410bd -r 472a938a46e3 libervia/cli/cmd_message.py --- a/libervia/cli/cmd_message.py Thu Sep 26 16:12:01 2024 +0200 +++ b/libervia/cli/cmd_message.py Thu Sep 26 16:12:01 2024 +0200 @@ -33,6 +33,9 @@ __commands__ = ["Message"] +RECIPIENTS_ARGS = ["to", "cc", "bcc"] +REPLY_ARGS = ["reply-to", "reply-room"] + class Send(base.CommandBase): def __init__(self, host): @@ -91,6 +94,35 @@ metavar="FILE_PATH", help=_("add a file as an attachment"), ) + + addressing_group = self.parser.add_argument_group( + "addressing commands", + description="Commands to add addressing metadata, and/or to send message to " + "multiple recipients." + ) + for arg_name in RECIPIENTS_ARGS: + addressing_group.add_argument( + f"--{arg_name}", + nargs="+", + action="append", + metavar=("JID", "DESCRIPTION"), + help=f'extra "{arg_name.upper()}" recipient(s), may be used several ' + 'times', + ) + for arg_name in REPLY_ARGS: + addressing_group.add_argument( + f"--{arg_name}", + nargs="+", + action="append", + metavar=("JID", "DESCRIPTION"), + help=f'ask to reply to this JID, may be used several ' + 'times', + ) + addressing_group.add_argument( + "--no-reply", + action="store_true", + help="flag this message as not requiring replies" + ) syntax = self.parser.add_mutually_exclusive_group() syntax.add_argument("-x", "--xhtml", action="store_true", help=_("XHTML body")) syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body")) @@ -117,6 +149,24 @@ extra[key] = clean_ustr("".join(stdin_lines)) stdin_lines = [] + addresses = {} + for arg_name in RECIPIENTS_ARGS + [a.replace("-", "_") for a in REPLY_ARGS]: + values = getattr(self.args, arg_name) + if values: + for value in values: + address_jid = value[0] + address_desc = " ".join(value[1:]).strip() + address = {"jid": address_jid} + if address_desc: + address["desc"] = address_desc + addresses.setdefault(arg_name.replace("_", ""), []).append(address) + + if self.args.no_reply: + addresses["noreply"] = True + + if addresses: + extra["addresses"] = addresses + to_send = [] error = False