Blob Blame History Raw
From dfb32883ee6e822289716bba82f4301bdf9d3c59 Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Mon, 7 Dec 2020 09:23:36 +0100
Subject: [PATCH 1/3] Command "update" renamed to "upgrade"

Compatibility with DNF.
DNF uses "upgrade". "update" is deprecated in DNF and is
only supported for compatibility.
---
 dnf/CMakeLists.txt                            |  8 ++--
 dnf/meson.build                               | 12 ++---
 .../update/dnf-command-update.gresource.xml   |  6 ---
 dnf/plugins/update/update.plugin              |  9 ----
 .../dnf-command-upgrade.c}                    | 44 +++++++++----------
 .../upgrade/dnf-command-upgrade.gresource.xml |  6 +++
 .../dnf-command-upgrade.h}                    |  8 ++--
 dnf/plugins/upgrade/upgrade.plugin            |  9 ++++
 8 files changed, 51 insertions(+), 51 deletions(-)
 delete mode 100644 dnf/plugins/update/dnf-command-update.gresource.xml
 delete mode 100644 dnf/plugins/update/update.plugin
 rename dnf/plugins/{update/dnf-command-update.c => upgrade/dnf-command-upgrade.c} (69%)
 create mode 100644 dnf/plugins/upgrade/dnf-command-upgrade.gresource.xml
 rename dnf/plugins/{update/dnf-command-update.h => upgrade/dnf-command-upgrade.h} (74%)
 create mode 100644 dnf/plugins/upgrade/upgrade.plugin

diff --git a/dnf/CMakeLists.txt b/dnf/CMakeLists.txt
index 1d640be..7f421f3 100644
--- a/dnf/CMakeLists.txt
+++ b/dnf/CMakeLists.txt
@@ -15,10 +15,10 @@ glib_compile_resources (DNF_COMMAND_REMOVE plugins/remove/dnf-command-remove.gre
                         INTERNAL)
 list (APPEND DNF_COMMAND_REMOVE "plugins/remove/dnf-command-remove.c")
 
-glib_compile_resources (DNF_COMMAND_UPDATE plugins/update/dnf-command-update.gresource.xml
-                        C_PREFIX dnf_command_update
+glib_compile_resources (DNF_COMMAND_UPGRADE plugins/upgrade/dnf-command-upgrade.gresource.xml
+                        C_PREFIX dnf_command_upgrade
                         INTERNAL)
-list (APPEND DNF_COMMAND_UPDATE "plugins/update/dnf-command-update.c")
+list (APPEND DNF_COMMAND_UPGRADE "plugins/upgrade/dnf-command-upgrade.c")
 
 glib_compile_resources (DNF_COMMAND_REPOLIST plugins/repolist/dnf-command-repolist.gresource.xml
                         C_PREFIX dnf_command_repolist
@@ -56,7 +56,7 @@ add_executable (microdnf dnf-main.c ${DNF_SRCS}
                 ${DNF_COMMAND_INSTALL}
                 ${DNF_COMMAND_REINSTALL}
                 ${DNF_COMMAND_REMOVE}
-                ${DNF_COMMAND_UPDATE}
+                ${DNF_COMMAND_UPGRADE}
                 ${DNF_COMMAND_REPOLIST}
                 ${DNF_COMMAND_REPOQUERY}
                 ${DNF_COMMAND_CLEAN}
diff --git a/dnf/meson.build b/dnf/meson.build
index b456202..4d4bd9e 100644
--- a/dnf/meson.build
+++ b/dnf/meson.build
@@ -30,14 +30,14 @@ microdnf_srcs = [
   ),
   'plugins/remove/dnf-command-remove.c',
 
-  # update
+  # upgrade
   gnome.compile_resources(
-    'dnf-update',
-    'plugins/update/dnf-command-update.gresource.xml',
-    c_name : 'dnf_command_update',
-    source_dir : 'plugins/update',
+    'dnf-upgrade',
+    'plugins/upgrade/dnf-command-upgrade.gresource.xml',
+    c_name : 'dnf_command_upgrade',
+    source_dir : 'plugins/upgrade',
   ),
-  'plugins/update/dnf-command-update.c',
+  'plugins/upgrade/dnf-command-upgrade.c',
 
   # repolist
   gnome.compile_resources(
diff --git a/dnf/plugins/update/dnf-command-update.gresource.xml b/dnf/plugins/update/dnf-command-update.gresource.xml
deleted file mode 100644
index 6168991..0000000
--- a/dnf/plugins/update/dnf-command-update.gresource.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<gresources>
-  <gresource prefix="/org/fedoraproject/dnf/plugins/update">
-    <file>update.plugin</file>
-  </gresource>
-</gresources>
diff --git a/dnf/plugins/update/update.plugin b/dnf/plugins/update/update.plugin
deleted file mode 100644
index a61b911..0000000
--- a/dnf/plugins/update/update.plugin
+++ /dev/null
@@ -1,9 +0,0 @@
-[Plugin]
-Module = command_update
-Embedded = dnf_command_update_register_types
-Name = update
-Description = Update packages
-Authors = Igor Gnatenko <ignatenko@redhat.com>
-License = GPL-3.0+
-Copyright = Copyright © 2016 Igor Gnatenko
-X-Command-Syntax = update [PACKAGE…]
diff --git a/dnf/plugins/update/dnf-command-update.c b/dnf/plugins/upgrade/dnf-command-upgrade.c
similarity index 69%
rename from dnf/plugins/update/dnf-command-update.c
rename to dnf/plugins/upgrade/dnf-command-upgrade.c
index 45ff797..5dc1c90 100644
--- a/dnf/plugins/update/dnf-command-update.c
+++ b/dnf/plugins/upgrade/dnf-command-upgrade.c
@@ -1,4 +1,4 @@
-/* dnf-command-update.c
+/* dnf-command-upgrade.c
  *
  * Copyright © 2016-2017 Igor Gnatenko <ignatenko@redhat.com>
  *
@@ -16,35 +16,35 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "dnf-command-update.h"
+#include "dnf-command-upgrade.h"
 #include "dnf-utils.h"
 
-struct _DnfCommandUpdate
+struct _DnfCommandUpgrade
 {
   PeasExtensionBase parent_instance;
 };
 
-static void dnf_command_update_iface_init (DnfCommandInterface *iface);
+static void dnf_command_upgrade_iface_init (DnfCommandInterface *iface);
 
-G_DEFINE_DYNAMIC_TYPE_EXTENDED (DnfCommandUpdate,
-                                dnf_command_update,
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (DnfCommandUpgrade,
+                                dnf_command_upgrade,
                                 PEAS_TYPE_EXTENSION_BASE,
                                 0,
                                 G_IMPLEMENT_INTERFACE (DNF_TYPE_COMMAND,
-                                                       dnf_command_update_iface_init))
+                                                       dnf_command_upgrade_iface_init))
 
 static void
-dnf_command_update_init (DnfCommandUpdate *self)
+dnf_command_upgrade_init (DnfCommandUpgrade *self)
 {
 }
 
 static gboolean
-dnf_command_update_run (DnfCommand      *cmd,
-                        int              argc,
-                        char            *argv[],
-                        GOptionContext  *opt_ctx,
-                        DnfContext      *ctx,
-                        GError         **error)
+dnf_command_upgrade_run (DnfCommand      *cmd,
+                         int              argc,
+                         char            *argv[],
+                         GOptionContext  *opt_ctx,
+                         DnfContext      *ctx,
+                         GError         **error)
 {
   g_auto(GStrv) pkgs = NULL;
   const GOptionEntry opts[] = {
@@ -63,7 +63,7 @@ dnf_command_update_run (DnfCommand      *cmd,
     }
   else
     {
-      /* Update each package */
+      /* Upgrade each package */
       for (GStrv pkg = pkgs; *pkg != NULL; pkg++)
         {
           if (!dnf_context_update (ctx, *pkg, error))
@@ -89,27 +89,27 @@ dnf_command_update_run (DnfCommand      *cmd,
 }
 
 static void
-dnf_command_update_class_init (DnfCommandUpdateClass *klass)
+dnf_command_upgrade_class_init (DnfCommandUpgradeClass *klass)
 {
 }
 
 static void
-dnf_command_update_iface_init (DnfCommandInterface *iface)
+dnf_command_upgrade_iface_init (DnfCommandInterface *iface)
 {
-  iface->run = dnf_command_update_run;
+  iface->run = dnf_command_upgrade_run;
 }
 
 static void
-dnf_command_update_class_finalize (DnfCommandUpdateClass *klass)
+dnf_command_upgrade_class_finalize (DnfCommandUpgradeClass *klass)
 {
 }
 
 G_MODULE_EXPORT void
-dnf_command_update_register_types (PeasObjectModule *module)
+dnf_command_upgrade_register_types (PeasObjectModule *module)
 {
-  dnf_command_update_register_type (G_TYPE_MODULE (module));
+  dnf_command_upgrade_register_type (G_TYPE_MODULE (module));
 
   peas_object_module_register_extension_type (module,
                                               DNF_TYPE_COMMAND,
-                                              DNF_TYPE_COMMAND_UPDATE);
+                                              DNF_TYPE_COMMAND_UPGRADE);
 }
diff --git a/dnf/plugins/upgrade/dnf-command-upgrade.gresource.xml b/dnf/plugins/upgrade/dnf-command-upgrade.gresource.xml
new file mode 100644
index 0000000..97c1ce4
--- /dev/null
+++ b/dnf/plugins/upgrade/dnf-command-upgrade.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/fedoraproject/dnf/plugins/upgrade">
+    <file>upgrade.plugin</file>
+  </gresource>
+</gresources>
diff --git a/dnf/plugins/update/dnf-command-update.h b/dnf/plugins/upgrade/dnf-command-upgrade.h
similarity index 74%
rename from dnf/plugins/update/dnf-command-update.h
rename to dnf/plugins/upgrade/dnf-command-upgrade.h
index 58bd228..5c8e976 100644
--- a/dnf/plugins/update/dnf-command-update.h
+++ b/dnf/plugins/upgrade/dnf-command-upgrade.h
@@ -1,4 +1,4 @@
-/* dnf-command-update.h
+/* dnf-command-upgrade.h
  *
  * Copyright © 2016 Igor Gnatenko <ignatenko@redhat.com>
  *
@@ -23,9 +23,9 @@
 
 G_BEGIN_DECLS
 
-#define DNF_TYPE_COMMAND_UPDATE dnf_command_update_get_type ()
-G_DECLARE_FINAL_TYPE (DnfCommandUpdate, dnf_command_update, DNF, COMMAND_UPDATE, PeasExtensionBase)
+#define DNF_TYPE_COMMAND_UPGRADE dnf_command_upgrade_get_type ()
+G_DECLARE_FINAL_TYPE (DnfCommandUpgrade, dnf_command_upgrade, DNF, COMMAND_UPGRADE, PeasExtensionBase)
 
-G_MODULE_EXPORT void dnf_command_update_register_types (PeasObjectModule *module);
+G_MODULE_EXPORT void dnf_command_upgrade_register_types (PeasObjectModule *module);
 
 G_END_DECLS
diff --git a/dnf/plugins/upgrade/upgrade.plugin b/dnf/plugins/upgrade/upgrade.plugin
new file mode 100644
index 0000000..1f2bda2
--- /dev/null
+++ b/dnf/plugins/upgrade/upgrade.plugin
@@ -0,0 +1,9 @@
+[Plugin]
+Module = command_upgrade
+Embedded = dnf_command_upgrade_register_types
+Name = upgrade
+Description = Upgrade packages
+Authors = Igor Gnatenko <ignatenko@redhat.com>
+License = GPL-2.0+
+Copyright = Copyright © 2016 Igor Gnatenko
+X-Command-Syntax = upgrade [PACKAGE…]
-- 
2.26.2


From 1bdeb23b66b44c4549a19e9c538c30833839156e Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Mon, 7 Dec 2020 12:25:48 +0100
Subject: [PATCH 2/3] Add support for command aliases

Added support for new custom keys to "*.plugin" file:
X-Alias-Name - command alias name
X-Alias-Description - description of alias

If both keys are present, then information will be added into help.
---
 dnf/dnf-main.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/dnf/dnf-main.c b/dnf/dnf-main.c
index 2ea3d76..0cf634f 100644
--- a/dnf/dnf-main.c
+++ b/dnf/dnf-main.c
@@ -358,6 +358,8 @@ main (int   argc,
   g_autoptr(GOptionContext) subcmd_opt_ctx = NULL;
   g_autofree gchar *subcmd_opt_param = NULL;
   GSList *cmds_with_subcmds = NULL;  /* list of commands with subcommands */
+  /* dictionary of aliases for commands */
+  g_autoptr(GHashTable) cmds_aliases = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
   setlocale (LC_ALL, "");
 
@@ -397,6 +399,7 @@ main (int   argc,
       if (peas_engine_provides_extension (engine, info, DNF_TYPE_COMMAND))
         {
           g_autofree gchar *command_name = g_strdup (peas_plugin_info_get_name (info));
+          g_autofree gchar *command_alias_name = g_strdup (peas_plugin_info_get_external_data (info, "Alias-Name"));
 
           /* Plugins with a '_' character in command name implement subcommands.
              E.g. the "command_module_enable" plugin implements the "enable" subcommand of the "module" command. */
@@ -409,11 +412,21 @@ main (int   argc,
                   break;
                 }
             }
+
+          /* Add command alias to the dictionary. */
+          if (command_alias_name)
+              g_hash_table_insert (cmds_aliases, g_strdup (command_alias_name), g_strdup (command_name));
+
           /*
            * At least 2 spaces between the command and its description are needed
            * so that help2man formats it correctly.
            */
           g_string_append_printf (cmd_summary, "\n  %-16s     %s", command_name, peas_plugin_info_get_description (info));
+
+          /* If command has an alias with a description, add it to the help. */
+          const gchar *command_alias_description = peas_plugin_info_get_external_data (info, "Alias-Description");
+          if (command_alias_name && command_alias_description)
+            g_string_append_printf (cmd_summary, "\n  %-16s     %s", command_alias_name, command_alias_description);
         }
     }
   g_option_context_set_summary (opt_ctx, cmd_summary->str);
@@ -552,15 +565,17 @@ main (int   argc,
    * Command name (cmd_name) can not contain '_' character. It is reserved for subcomands. */
   if (cmd_name != NULL && strchr(cmd_name, '_') == NULL)
     {
-      with_subcmds = g_slist_find_custom (cmds_with_subcmds, cmd_name, compare_strings) != NULL;
-      g_autofree gchar *mod_name = g_strdup_printf ("command_%s", cmd_name);
+      const gchar *original_cmd_name = g_hash_table_lookup (cmds_aliases, cmd_name);
+      const gchar *search_cmd_name = original_cmd_name ? original_cmd_name : cmd_name;
+      with_subcmds = g_slist_find_custom (cmds_with_subcmds, search_cmd_name, compare_strings) != NULL;
+      g_autofree gchar *mod_name = g_strdup_printf ("command_%s", search_cmd_name);
       plug = peas_engine_get_plugin_info (engine, mod_name);
       if (plug == NULL && with_subcmds)
         {
           subcmd_name = get_command (&argc, argv);
           if (subcmd_name != NULL)
             {
-              g_autofree gchar *submod_name = g_strdup_printf ("command_%s_%s", cmd_name, subcmd_name);
+              g_autofree gchar *submod_name = g_strdup_printf ("command_%s_%s", search_cmd_name, subcmd_name);
               plug = peas_engine_get_plugin_info (engine, submod_name);
             }
         }
-- 
2.26.2


From 74a918e84a2250c02dcf2190f4951eab2a3e3296 Mon Sep 17 00:00:00 2001
From: Jaroslav Rohel <jrohel@redhat.com>
Date: Mon, 7 Dec 2020 12:30:05 +0100
Subject: [PATCH 3/3] Added alias "update" to "upgrade" command

"Update" is deprecated, but is required for compatibility.
---
 dnf/plugins/upgrade/upgrade.plugin | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/dnf/plugins/upgrade/upgrade.plugin b/dnf/plugins/upgrade/upgrade.plugin
index 1f2bda2..87dd93e 100644
--- a/dnf/plugins/upgrade/upgrade.plugin
+++ b/dnf/plugins/upgrade/upgrade.plugin
@@ -7,3 +7,5 @@ Authors = Igor Gnatenko <ignatenko@redhat.com>
 License = GPL-2.0+
 Copyright = Copyright © 2016 Igor Gnatenko
 X-Command-Syntax = upgrade [PACKAGE…]
+X-Alias-Name = update
+X-Alias-Description = Compatibility alias for the "upgrade" command
-- 
2.26.2