changeset 3938:6939594ba77e

cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption: rel 380
author Goffi <goffi@goffi.org>
date Sat, 15 Oct 2022 20:37:00 +0200
parents 5980ea188f87
children 8ae3e870be94
files sat_frontends/jp/base.py sat_frontends/jp/cmd_pubsub.py
diffstat 2 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/base.py	Sat Oct 15 20:37:00 2022 +0200
+++ b/sat_frontends/jp/base.py	Sat Oct 15 20:37:00 2022 +0200
@@ -34,7 +34,7 @@
 import termios
 from pathlib import Path
 from glob import iglob
-from typing import Optional, Set
+from typing import Optional, Set, Union
 from importlib import import_module
 from sat_frontends.tools.jid import JID
 from sat.tools import config
@@ -979,26 +979,35 @@
         return full_jid.rsplit("/", 1)[0]
 
 
-class CommandBase(object):
+class CommandBase:
 
-    def __init__(self, host, name, use_profile=True, use_output=False, extra_outputs=None,
-                       need_connect=None, help=None, **kwargs):
+    def __init__(
+        self,
+        host: LiberviaCli,
+        name: str,
+        use_profile: bool = True,
+        use_output: Union[bool, str] = False,
+        extra_outputs: Optional[dict] = None,
+        need_connect: Optional[bool] = None,
+        help: Optional[str] = None,
+        **kwargs
+    ):
         """Initialise CommandBase
 
         @param host: Jp instance
-        @param name(unicode): name of the new command
-        @param use_profile(bool): if True, add profile selection/connection commands
-        @param use_output(bool, unicode): if not False, add --output option
-        @param extra_outputs(dict): list of command specific outputs:
+        @param name: name of the new command
+        @param use_profile: if True, add profile selection/connection commands
+        @param use_output: if not False, add --output option
+        @param extra_outputs: list of command specific outputs:
             key is output name ("default" to use as main output)
             value is a callable which will format the output (data will be used as only
             argument)
             if a key already exists with normal outputs, the extra one will be used
-        @param need_connect(bool, None): True if profile connection is needed
+        @param need_connect: True if profile connection is needed
             False else (profile session must still be started)
             None to set auto value (i.e. True if use_profile is set)
             Can't be set if use_profile is False
-        @param help(unicode): help message to display
+        @param help: help message to display
         @param **kwargs: args passed to ArgumentParser
             use_* are handled directly, they can be:
             - use_progress(bool): if True, add progress bar activation option
--- a/sat_frontends/jp/cmd_pubsub.py	Sat Oct 15 20:37:00 2022 +0200
+++ b/sat_frontends/jp/cmd_pubsub.py	Sat Oct 15 20:37:00 2022 +0200
@@ -1281,9 +1281,17 @@
             default="",
             help=_("subscription id"),
         )
+        self.parser.add_argument(
+            "--no-decrypt",
+            action="store_true",
+            help=_("don't do automatic decryption of e2ee items"),
+        )
         #  TODO: a key(s) argument to select keys to display
 
     async def start(self):
+        extra = {}
+        if self.args.no_decrypt:
+            extra["decrypt"] = False
         try:
             ps_result = data_format.deserialise(
                 await self.host.bridge.psItemsGet(
@@ -1292,7 +1300,7 @@
                     self.args.max,
                     self.args.items,
                     self.args.sub_id,
-                    self.getPubsubExtra(),
+                    self.getPubsubExtra(extra),
                     self.profile,
                 )
             )