[gnome-shell] extensions-tool: Add 'uninstall' command



commit 2df77579058192a606b39ef6991897b8406a7ac5
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 11 22:35:49 2019 +0200

    extensions-tool: Add 'uninstall' command
    
    Uninstall is another action that can be useful from the command line,
    so expose that as well.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/1234

 src/extensions-tool/command-uninstall.c            | 99 ++++++++++++++++++++++
 src/extensions-tool/commands.h                     |  1 +
 .../completion/bash/gnome-extensions               |  7 +-
 src/extensions-tool/main.c                         |  3 +
 src/extensions-tool/man/gnome-extensions.txt       |  6 ++
 src/extensions-tool/meson.build                    |  1 +
 6 files changed, 115 insertions(+), 2 deletions(-)
---
diff --git a/src/extensions-tool/command-uninstall.c b/src/extensions-tool/command-uninstall.c
new file mode 100644
index 0000000000..757de6d1b9
--- /dev/null
+++ b/src/extensions-tool/command-uninstall.c
@@ -0,0 +1,99 @@
+/* commands-uninstall.c
+ *
+ * Copyright 2019 Florian Müllner <fmuellner gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "commands.h"
+#include "common.h"
+#include "config.h"
+
+static gboolean
+uninstall_extension (const char *uuid)
+{
+  g_autoptr (GDBusProxy) proxy = NULL;
+  g_autoptr (GVariant) response = NULL;
+  g_autoptr (GError) error = NULL;
+  gboolean success = FALSE;
+
+  proxy = get_shell_proxy (&error);
+  if (proxy == NULL)
+    return FALSE;
+
+  response = g_dbus_proxy_call_sync (proxy,
+                                     "UninstallExtension",
+                                     g_variant_new ("(s)", uuid),
+                                     0,
+                                     -1,
+                                     NULL,
+                                     &error);
+  if (response == NULL)
+    return FALSE;
+
+  g_variant_get (response, "(b)", &success);
+
+  return success;
+}
+
+int
+handle_uninstall (int argc, char *argv[], gboolean do_help)
+{
+  g_autoptr (GOptionContext) context = NULL;
+  g_autoptr (GError) error = NULL;
+  g_auto(GStrv) uuids = NULL;
+  GOptionEntry entries[] = {
+    { .long_name = G_OPTION_REMAINING,
+      .arg_description = "UUID",
+      .arg = G_OPTION_ARG_STRING_ARRAY, .arg_data = &uuids },
+    { NULL }
+  };
+
+  g_set_prgname ("gnome-extensions uninstall");
+
+  context = g_option_context_new (NULL);
+  g_option_context_set_help_enabled (context, FALSE);
+  g_option_context_set_summary (context, _("Uninstall an extension"));
+  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+
+  if (do_help)
+    {
+      show_help (context, NULL);
+      return 0;
+    }
+
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+      show_help (context, error->message);
+      return 1;
+    }
+
+  if (uuids == NULL)
+    {
+      show_help (context, _("No UUID given"));
+      return 1;
+    }
+  else if (g_strv_length (uuids) > 1)
+    {
+      show_help (context, _("More than one UUID given"));
+      return 1;
+    }
+
+  return uninstall_extension (*uuids) ? 0 : 2;
+}
diff --git a/src/extensions-tool/commands.h b/src/extensions-tool/commands.h
index 04de71c7c1..e8c05eec3b 100644
--- a/src/extensions-tool/commands.h
+++ b/src/extensions-tool/commands.h
@@ -32,5 +32,6 @@ int handle_prefs      (int argc, char *argv[], gboolean do_help);
 int handle_create     (int argc, char *argv[], gboolean do_help);
 int handle_pack       (int argc, char *argv[], gboolean do_help);
 int handle_install    (int argc, char *argv[], gboolean do_help);
+int handle_uninstall  (int argc, char *argv[], gboolean do_help);
 
 G_END_DECLS
diff --git a/src/extensions-tool/completion/bash/gnome-extensions 
b/src/extensions-tool/completion/bash/gnome-extensions
index aaff309c08..56bda405f5 100644
--- a/src/extensions-tool/completion/bash/gnome-extensions
+++ b/src/extensions-tool/completion/bash/gnome-extensions
@@ -5,7 +5,7 @@
 ################################################################################
 
 __gnome_extensions() {
-  local commands="version enable disable info install show list create pack prefs"
+  local commands="version enable disable info install show list create pack prefs uninstall"
   local COMMAND=${COMP_WORDS[1]}
 
   _init_completion -s || return
@@ -32,7 +32,10 @@ __gnome_extensions() {
         prefs)
           local list_opt=--prefs
           ;;&
-        enable|disable|info|show|prefs)
+        uninstall)
+          local list_opt=--user
+          ;;&
+        enable|disable|info|show|prefs|uninstall)
           COMPREPLY=($(compgen -W "`gnome-extensions list $list_opt`" -- "$2"))
           return 0
           ;;
diff --git a/src/extensions-tool/main.c b/src/extensions-tool/main.c
index ef94abc5f7..e6792ad64b 100644
--- a/src/extensions-tool/main.c
+++ b/src/extensions-tool/main.c
@@ -183,6 +183,7 @@ usage (void)
   g_printerr ("  version   %s\n", _("Print version"));
   g_printerr ("  enable    %s\n", _("Enable extension"));
   g_printerr ("  disable   %s\n", _("Disable extension"));
+  g_printerr ("  uninstall %s\n", _("Uninstall extension"));
   g_printerr ("  list      %s\n", _("List extensions"));
   g_printerr ("  info      %s\n", _("Show extension info"));
   g_printerr ("  show      %s\n", _("Show extension info"));
@@ -261,6 +262,8 @@ main (int argc, char *argv[])
     return handle_pack (argc, argv, do_help);
   else if (g_str_equal (command, "install"))
     return handle_install (argc, argv, do_help);
+  else if (g_str_equal (command, "uninstall"))
+    return handle_uninstall (argc, argv, do_help);
   else
     usage ();
 
diff --git a/src/extensions-tool/man/gnome-extensions.txt b/src/extensions-tool/man/gnome-extensions.txt
index 2322f6d312..db768582a4 100644
--- a/src/extensions-tool/man/gnome-extensions.txt
+++ b/src/extensions-tool/man/gnome-extensions.txt
@@ -33,6 +33,8 @@ SYNOPSIS
 
 *gnome-extensions* install ['OPTION'...] 'PACK'
 
+*gnome-extensions* uninstall 'UUID'
+
 DESCRIPTION
 -----------
 *gnome-extensions* is a utility that makes some common GNOME extensions
@@ -175,6 +177,10 @@ reviewing their content.
   *--force*:::
     Override an existing extension
 
+*uninstall* 'UUID'::
+Uninstalls the extension identified by 'UUID'.
+
+
 EXIT STATUS
 -----------
 On success 0 is returned, a non-zero failure code otherwise.
diff --git a/src/extensions-tool/meson.build b/src/extensions-tool/meson.build
index ab93e85c8f..ae646c28c2 100644
--- a/src/extensions-tool/meson.build
+++ b/src/extensions-tool/meson.build
@@ -17,6 +17,7 @@ sources = [
   'command-list.c',
   'command-pack.c',
   'command-prefs.c',
+  'command-uninstall.c',
   'main.c'
 ]
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]