test: improvements for GAppInfo test

· Add a usage output that is printed when called with no argument
   or with '--help' argument. This is helpful as it avoids having
   to read the source code to know how to run the different options.

 · Adds new '--should-show-only' option to 'search' command, to
   better mimick the gnome-shell app search, by not returning
   apps with NoDisplay=true.

  Example for running a desktop app search with the new option from
  inside the GLib build dir:
    $ gio/tests/apps search --should-show-only settings
This commit is contained in:
Nelson Benítez León 2023-09-25 03:01:59 +01:00 committed by Philip Withnall
parent 1cd0dfa55b
commit 3c22e2745c

View File

@ -33,8 +33,13 @@ main (int argc, char **argv)
{
setlocale (LC_ALL, "");
if (argv[1] == NULL)
;
if (argv[1] == NULL || g_str_equal (argv[1], "--help"))
g_print ("Usage:\n apps --help\n apps COMMAND [COMMAND_OPTIONS]\n\nCOMMANDS:\n list\n "
"search [--should-show-only] TEXT_TO_SEARCH\n implementations INTERFACE_NAME\n "
"show-info DESKTOP_FILE\n default-for-type MIME_TYPE\n recommended-for-type MIME_TYPE\n "
"all-for-type MIME_TYPE\n fallback-for-type MIME_TYPE\n should-show DESKTOP_FILE\n "
"monitor\n\nExamples:\n apps search --should-show-only ter\n"
" apps show-info org.gnome.Nautilus.desktop\n apps default-for-type image/png\n\n");
else if (g_str_equal (argv[1], "list"))
{
GList *all, *i;
@ -47,13 +52,31 @@ main (int argc, char **argv)
else if (g_str_equal (argv[1], "search"))
{
gchar ***results;
gboolean should_show_only;
gint i, j;
results = g_desktop_app_info_search (argv[2]);
should_show_only = argc > 3 && g_str_equal (argv[2], "--should-show-only");
results = g_desktop_app_info_search (argv[ should_show_only ? 3 : 2 ]);
for (i = 0; results[i]; i++)
{
for (j = 0; results[i][j]; j++)
{
if (should_show_only)
{
GDesktopAppInfo *info;
gboolean should_show;
info = g_desktop_app_info_new (results[i][j]);
if (info)
{
should_show = g_app_info_should_show (G_APP_INFO (info));
g_object_unref (info);
if (!should_show)
continue;
}
}
g_print ("%s%s", j ? " " : "", results[i][j]);
}
g_print ("\n");
g_strfreev (results[i]);
}