[tracker/wip/carlosg/cli-split: 3/4] tracker: Show external commands on command summary



commit 0f4f8853c1a70bc77b536082c71eb0f8d98c3fc7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Dec 19 20:30:47 2019 +0100

    tracker: Show external commands on command summary
    
    This allows discovery, and also allows the bash completion script to
    list those.

 src/tracker/meson.build    |  1 +
 src/tracker/tracker-main.c | 45 +++++++++++++++++++++++++++++++++++++++------
 2 files changed, 40 insertions(+), 6 deletions(-)
---
diff --git a/src/tracker/meson.build b/src/tracker/meson.build
index af6e5f7b7..530166114 100644
--- a/src/tracker/meson.build
+++ b/src/tracker/meson.build
@@ -17,6 +17,7 @@ executable('tracker', sources,
     c_args: tracker_c_args + [
         '-DLIBEXECDIR="@0@"'.format(join_paths(get_option('prefix'), get_option('libexecdir'))),
         '-DMANDIR="@0@"'.format(join_paths(get_option('prefix'), get_option('datadir'), 'man')),
+        '-DBINDIR="@0@"'.format(join_paths(get_option('prefix'), get_option('bindir'))),
     ],
     install: true,
     install_rpath: tracker_install_rpath,
diff --git a/src/tracker/tracker-main.c b/src/tracker/tracker-main.c
index b65ee5bbc..4ac027ba9 100644
--- a/src/tracker/tracker-main.c
+++ b/src/tracker/tracker-main.c
@@ -155,6 +155,10 @@ static void
 print_usage_list_cmds (void)
 {
        int i, longest = 0;
+       GList *extra_commands = NULL;
+       GFileEnumerator *enumerator;
+       GFileInfo *info;
+       GFile *dir;
 
        for (i = 0; i < G_N_ELEMENTS(commands); i++) {
                if (longest < strlen (commands[i].cmd))
@@ -164,16 +168,45 @@ print_usage_list_cmds (void)
        puts (_("Available tracker commands are:"));
 
        for (i = 0; i < G_N_ELEMENTS(commands); i++) {
-               /* Don't list version in commands */
-               if (!strcmp (commands[i].cmd, "version") ||
-                   !strcmp (commands[i].cmd, "help")) {
-                       continue;
-               }
-
                g_print ("   %s   ", commands[i].cmd);
                mput_char (' ', longest - strlen (commands[i].cmd));
                puts (_(commands[i].help));
        }
+
+       dir = g_file_new_for_path (LIBEXECDIR "/tracker/");
+       enumerator = g_file_enumerate_children (dir,
+                                               G_FILE_ATTRIBUTE_STANDARD_NAME ","
+                                               G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK ","
+                                               G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
+                                               G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                               NULL, NULL);
+       g_object_unref (dir);
+
+       while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
+               /* Filter builtin commands */
+               if (g_file_info_get_is_symlink (info) &&
+                   g_strcmp0 (g_file_info_get_symlink_target (info), BINDIR "/tracker") == 0)
+                       continue;
+
+               extra_commands = g_list_prepend (extra_commands,
+                                                g_strdup (g_file_info_get_name (info)));
+               g_object_unref (info);
+       }
+
+       g_object_unref (enumerator);
+
+       if (extra_commands) {
+               extra_commands = g_list_sort (extra_commands, (GCompareFunc) g_strcmp0);
+
+               g_print ("\n");
+               puts (_("Additional / third party commands are:"));
+
+               while (extra_commands) {
+                       g_print ("   %s   \n", (gchar *) extra_commands->data);
+                       g_free (extra_commands->data);
+                       extra_commands = g_list_remove (extra_commands, extra_commands->data);
+               }
+       }
 }
 
 static void


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