[gnome-shell] extensions-tool: Add common option to silence errors



commit f5a170ce46be439be7c5a63446d486a0e2e75012
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Mar 14 12:58:04 2020 +0100

    extensions-tool: Add common option to silence errors
    
    Error reporting is useful when used interactively, but often undesirable
    when used in scripts. Account for that with a common --quiet option,
    which is more convenient than redirection stderr to /dev/null.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/2391

 .../extensions-tool/man/gnome-extensions.txt       |  7 +++++
 subprojects/extensions-tool/src/command-create.c   |  1 +
 subprojects/extensions-tool/src/command-disable.c  |  1 +
 subprojects/extensions-tool/src/command-enable.c   |  1 +
 subprojects/extensions-tool/src/command-info.c     |  1 +
 subprojects/extensions-tool/src/command-install.c  |  1 +
 subprojects/extensions-tool/src/command-list.c     |  1 +
 subprojects/extensions-tool/src/command-pack.c     |  1 +
 subprojects/extensions-tool/src/command-prefs.c    |  1 +
 subprojects/extensions-tool/src/command-reset.c    |  2 ++
 .../extensions-tool/src/command-uninstall.c        |  1 +
 subprojects/extensions-tool/src/common.h           |  2 ++
 subprojects/extensions-tool/src/main.c             | 33 ++++++++++++++++++++++
 13 files changed, 53 insertions(+)
---
diff --git a/subprojects/extensions-tool/man/gnome-extensions.txt 
b/subprojects/extensions-tool/man/gnome-extensions.txt
index 125c9b82ce..d94c0bd2e3 100644
--- a/subprojects/extensions-tool/man/gnome-extensions.txt
+++ b/subprojects/extensions-tool/man/gnome-extensions.txt
@@ -42,6 +42,13 @@ DESCRIPTION
 *gnome-extensions* is a utility that makes some common GNOME extensions
 operations available on the command line.
 
+COMMON OPTIONS
+--------------
+All commands except for *help* and *version* handle the following options:
+
+*--quiet*, *-q*::
+Do not print error messages
+
 COMMANDS
 --------
 *help* ['COMMAND']::
diff --git a/subprojects/extensions-tool/src/command-create.c 
b/subprojects/extensions-tool/src/command-create.c
index e32e7c262b..7fb5d7a78f 100644
--- a/subprojects/extensions-tool/src/command-create.c
+++ b/subprojects/extensions-tool/src/command-create.c
@@ -262,6 +262,7 @@ handle_create (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("Create a new extension"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group ());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-disable.c 
b/subprojects/extensions-tool/src/command-disable.c
index aa8efab5bc..116f6699cb 100644
--- a/subprojects/extensions-tool/src/command-disable.c
+++ b/subprojects/extensions-tool/src/command-disable.c
@@ -56,6 +56,7 @@ handle_disable (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("Disable an extension"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-enable.c 
b/subprojects/extensions-tool/src/command-enable.c
index c790ec95f3..786e451095 100644
--- a/subprojects/extensions-tool/src/command-enable.c
+++ b/subprojects/extensions-tool/src/command-enable.c
@@ -56,6 +56,7 @@ handle_enable (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("Enable an extension"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-info.c b/subprojects/extensions-tool/src/command-info.c
index a0ae0c6ac8..e280023e1c 100644
--- a/subprojects/extensions-tool/src/command-info.c
+++ b/subprojects/extensions-tool/src/command-info.c
@@ -78,6 +78,7 @@ handle_info (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("Show extensions info"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-install.c 
b/subprojects/extensions-tool/src/command-install.c
index 501f9502c8..2eefabafa3 100644
--- a/subprojects/extensions-tool/src/command-install.c
+++ b/subprojects/extensions-tool/src/command-install.c
@@ -183,6 +183,7 @@ handle_install (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("Install an extension bundle"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-list.c b/subprojects/extensions-tool/src/command-list.c
index f92dafa4ee..bc021fd14e 100644
--- a/subprojects/extensions-tool/src/command-list.c
+++ b/subprojects/extensions-tool/src/command-list.c
@@ -150,6 +150,7 @@ handle_list (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("List installed extensions"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-pack.c b/subprojects/extensions-tool/src/command-pack.c
index d98e8fa4fb..c8d9950065 100644
--- a/subprojects/extensions-tool/src/command-pack.c
+++ b/subprojects/extensions-tool/src/command-pack.c
@@ -480,6 +480,7 @@ handle_pack (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("Create an extension bundle"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-prefs.c b/subprojects/extensions-tool/src/command-prefs.c
index 693d48406a..86799eafc5 100644
--- a/subprojects/extensions-tool/src/command-prefs.c
+++ b/subprojects/extensions-tool/src/command-prefs.c
@@ -89,6 +89,7 @@ handle_prefs (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("Opens extension preferences"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-reset.c b/subprojects/extensions-tool/src/command-reset.c
index 32b5fbaf24..2615f1595c 100644
--- a/subprojects/extensions-tool/src/command-reset.c
+++ b/subprojects/extensions-tool/src/command-reset.c
@@ -1,4 +1,5 @@
 /* command-reset.c
+  g_option_context_add_group (context, get_option_group());
  *
  * Copyright 2019 Florian Müllner <fmuellner gnome org>
  *
@@ -56,6 +57,7 @@ handle_reset (int argc, char *argv[], gboolean do_help)
   g_option_context_set_help_enabled (context, FALSE);
   g_option_context_set_summary (context, _("Reset an extension"));
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/command-uninstall.c 
b/subprojects/extensions-tool/src/command-uninstall.c
index 757de6d1b9..5974e098e1 100644
--- a/subprojects/extensions-tool/src/command-uninstall.c
+++ b/subprojects/extensions-tool/src/command-uninstall.c
@@ -71,6 +71,7 @@ handle_uninstall (int argc, char *argv[], gboolean do_help)
   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);
+  g_option_context_add_group (context, get_option_group());
 
   if (do_help)
     {
diff --git a/subprojects/extensions-tool/src/common.h b/subprojects/extensions-tool/src/common.h
index 32f4b788b8..fb23b65804 100644
--- a/subprojects/extensions-tool/src/common.h
+++ b/subprojects/extensions-tool/src/common.h
@@ -45,6 +45,8 @@ typedef enum {
   DISPLAY_DETAILED
 } DisplayFormat;
 
+GOptionGroup *get_option_group (void);
+
 void show_help (GOptionContext *context,
                 const char     *message);
 
diff --git a/subprojects/extensions-tool/src/main.c b/subprojects/extensions-tool/src/main.c
index 62d383db7d..cc7cd80cd6 100644
--- a/subprojects/extensions-tool/src/main.c
+++ b/subprojects/extensions-tool/src/main.c
@@ -49,6 +49,39 @@ extension_state_to_string (ExtensionState state)
   return "UNKNOWN";
 }
 
+static void
+print_nothing (const char *message)
+{
+}
+
+static gboolean
+quiet_cb (const gchar  *option_name,
+          const gchar  *value,
+          gpointer      data,
+          GError      **error)
+{
+  g_set_printerr_handler (print_nothing);
+  return TRUE;
+}
+
+GOptionGroup *
+get_option_group ()
+{
+  GOptionEntry entries[] = {
+    { .long_name = "quiet", .short_name = 'q',
+      .description = _("Do not print error messages"),
+      .arg = G_OPTION_ARG_CALLBACK, .arg_data = &quiet_cb,
+      .flags = G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_IN_MAIN },
+    { NULL }
+  };
+  GOptionGroup *group;
+
+  group = g_option_group_new ("Common", "common options", "common options", NULL, NULL);
+  g_option_group_add_entries (group, entries);
+
+  return group;
+}
+
 void
 show_help (GOptionContext *context, const char *message)
 {


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