changeset 3414:ffe7a6d6018a

jp (roster): `delete` implementation
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:16 +0100
parents f4d417593e77
children 814e118d9ef3
files doc/jp/roster.rst sat_frontends/jp/cmd_roster.py
diffstat 2 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/doc/jp/roster.rst	Thu Nov 12 14:53:16 2020 +0100
+++ b/doc/jp/roster.rst	Thu Nov 12 14:53:16 2020 +0100
@@ -72,6 +72,18 @@
 
   $ jp roster set --replace -g friends -g housemates pierre@example.net
 
+delete
+======
+
+Remove an entity from roster.
+
+examples
+--------
+
+Remove John from your roster::
+
+  $ jp roster delete john@example.net
+
 stats
 =====
 
--- a/sat_frontends/jp/cmd_roster.py	Thu Nov 12 14:53:16 2020 +0100
+++ b/sat_frontends/jp/cmd_roster.py	Thu Nov 12 14:53:16 2020 +0100
@@ -125,6 +125,33 @@
         self.host.quit()
 
 
+class Delete(base.CommandBase):
+
+    def __init__(self, host):
+        super().__init__(host, 'delete', help=_('remove an entity from roster'))
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "-f", "--force", action="store_true", help=_("delete without confirmation")
+        )
+        self.parser.add_argument(
+            "jid", help=_("jid of the roster entity"))
+
+    async def start(self):
+        if not self.args.force:
+            message = _("Are you sure to delete {entity} fril your roster?").format(
+                entity=self.args.jid
+            )
+            await self.host.confirmOrQuit(message, _("entity deletion cancelled"))
+        try:
+            await self.host.bridge.delContact(
+                self.args.jid, self.host.profile)
+        except Exception as e:
+            self.disp(f"error while deleting the entity: {e}", error=True)
+            self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+        self.host.quit()
+
+
 class Stats(base.CommandBase):
 
     def __init__(self, host):
@@ -293,7 +320,7 @@
 
 
 class Roster(base.CommandBase):
-    subcommands = (Get, Set, Stats, Purge, Resync)
+    subcommands = (Get, Set, Delete, Stats, Purge, Resync)
 
     def __init__(self, host):
         super(Roster, self).__init__(