From 025fa4e4d685a905f8b2e371a0b9d66fd5cdb6c1 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 13 Jan 2016 17:02:15 +0100 Subject: [PATCH] Merge list-apps and list-runtimes into single list command --- app/xdg-app-builtins-list.c | 88 +++++++---- app/xdg-app-builtins.h | 5 +- app/xdg-app-main.c | 5 +- doc/Makefile.am | 3 +- doc/xdg-app-list-runtimes.xml | 138 ------------------ ...xdg-app-list-apps.xml => xdg-app-list.xml} | 35 ++++- 6 files changed, 97 insertions(+), 177 deletions(-) delete mode 100644 doc/xdg-app-list-runtimes.xml rename doc/{xdg-app-list-apps.xml => xdg-app-list.xml} (77%) diff --git a/app/xdg-app-builtins-list.c b/app/xdg-app-builtins-list.c index 9e0fe1cc..9dd6b32f 100644 --- a/app/xdg-app-builtins-list.c +++ b/app/xdg-app-builtins-list.c @@ -34,20 +34,53 @@ static gboolean opt_show_details; static gboolean opt_user; static gboolean opt_system; +static gboolean opt_runtime; +static gboolean opt_app; static GOptionEntry options[] = { { "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, "Show user installations", NULL }, { "system", 0, 0, G_OPTION_ARG_NONE, &opt_system, "Show system-wide installations", NULL }, { "show-details", 'd', 0, G_OPTION_ARG_NONE, &opt_show_details, "Show arches and branches", NULL }, + { "runtime", 0, 0, G_OPTION_ARG_NONE, &opt_runtime, "List installed runtimes", }, + { "app", 0, 0, G_OPTION_ARG_NONE, &opt_app, "List installed applications", }, { NULL } }; +static char ** +join_strv (char **a, char **b) +{ + gsize len = 1, i, j; + char **res; + + if (a) + len += g_strv_length (a); + if (b) + len += g_strv_length (b); + + res = g_new (char *, len); + + i = 0; + + for (j = 0; a != NULL && a[j] != NULL; j++) + res[i++] = g_strdup (a[j]); + + for (j = 0; b != NULL && b[j] != NULL; j++) + res[i++] = g_strdup (b[j]); + + res[i++] = NULL; + return res; +} + static gboolean -print_installed_refs (const char *kind, gboolean print_system, gboolean print_user, GCancellable *cancellable, GError **error) +print_installed_refs (gboolean app, gboolean runtime, gboolean print_system, gboolean print_user, GCancellable *cancellable, GError **error) { g_autofree char *last = NULL; g_auto(GStrv) system = NULL; + g_auto(GStrv) system_app = NULL; + g_auto(GStrv) system_runtime = NULL; g_auto(GStrv) user = NULL; + g_auto(GStrv) user_app = NULL; + g_auto(GStrv) user_runtime = NULL; int s, u; if (print_user) @@ -58,7 +91,9 @@ print_installed_refs (const char *kind, gboolean print_system, gboolean print_us if (xdg_app_dir_ensure_repo (dir, cancellable, NULL)) { - if (!xdg_app_dir_list_refs (dir, kind, &user, cancellable, error)) + if (app && !xdg_app_dir_list_refs (dir, "app", &user_app, cancellable, error)) + return FALSE; + if (runtime && !xdg_app_dir_list_refs (dir, "runtime", &user_runtime, cancellable, error)) return FALSE; } } @@ -70,17 +105,17 @@ print_installed_refs (const char *kind, gboolean print_system, gboolean print_us dir = xdg_app_dir_get (FALSE); if (xdg_app_dir_ensure_repo (dir, cancellable, NULL)) { - if (!xdg_app_dir_list_refs (dir, kind, &system, cancellable, error)) + if (app && !xdg_app_dir_list_refs (dir, "app", &system_app, cancellable, error)) + return FALSE; + if (runtime && !xdg_app_dir_list_refs (dir, "runtime", &system_runtime, cancellable, error)) return FALSE; } } XdgAppTablePrinter *printer = xdg_app_table_printer_new (); - if (user == NULL) - user = g_new0 (char *, 1); - if (system == NULL) - system = g_new0 (char *, 1); + user = join_strv (user_app, user_runtime); + system = join_strv (system_app, system_runtime); for (s = 0, u = 0; system[s] != NULL || user[u] != NULL; ) { @@ -142,7 +177,7 @@ print_installed_refs (const char *kind, gboolean print_system, gboolean print_us if (print_user && print_system) xdg_app_table_printer_append_with_comma (printer, is_user ? "user" : "system"); - if (strcmp (kind, "app") == 0) + if (strcmp (parts[0], "app") == 0) { g_autofree char *current; @@ -150,6 +185,11 @@ print_installed_refs (const char *kind, gboolean print_system, gboolean print_us if (current && strcmp (ref, current) == 0) xdg_app_table_printer_append_with_comma (printer, "current"); } + else + { + if (app) + xdg_app_table_printer_append_with_comma (printer, "runtime"); + } } else { @@ -170,16 +210,19 @@ print_installed_refs (const char *kind, gboolean print_system, gboolean print_us } gboolean -xdg_app_builtin_list_runtimes (int argc, char **argv, GCancellable *cancellable, GError **error) +xdg_app_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; - context = g_option_context_new (" - List installed runtimes"); + context = g_option_context_new (" - List installed apps and/or runtimes"); if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; - if (!print_installed_refs ("runtime", + if (!opt_app && !opt_runtime) + opt_app = TRUE; + + if (!print_installed_refs (opt_app, opt_runtime, opt_system || (!opt_user && !opt_system), opt_user || (!opt_user && !opt_system), cancellable, error)) @@ -188,21 +231,16 @@ xdg_app_builtin_list_runtimes (int argc, char **argv, GCancellable *cancellable, return TRUE; } +gboolean +xdg_app_builtin_list_runtimes (int argc, char **argv, GCancellable *cancellable, GError **error) +{ + opt_runtime = TRUE; + return xdg_app_builtin_list (argc, argv, cancellable, error); +} + gboolean xdg_app_builtin_list_apps (int argc, char **argv, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - - context = g_option_context_new (" - List installed applications"); - - if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) - return FALSE; - - if (!print_installed_refs ("app", - opt_system || (!opt_user && !opt_system), - opt_user || (!opt_user && !opt_system), - cancellable, error)) - return FALSE; - - return TRUE; + opt_app = TRUE; + return xdg_app_builtin_list (argc, argv, cancellable, error); } diff --git a/app/xdg-app-builtins.h b/app/xdg-app-builtins.h index e269e946..9c7a438b 100644 --- a/app/xdg-app-builtins.h +++ b/app/xdg-app-builtins.h @@ -55,11 +55,10 @@ BUILTINPROTO(ls_remote); BUILTINPROTO(list_remotes); BUILTINPROTO(install); BUILTINPROTO(update); -BUILTINPROTO(list_runtimes); BUILTINPROTO(make_current_app); BUILTINPROTO(uninstall); BUILTINPROTO(install_bundle); -BUILTINPROTO(list_apps); +BUILTINPROTO(list); BUILTINPROTO(run); BUILTINPROTO(enter); BUILTINPROTO(build_init); @@ -78,6 +77,8 @@ BUILTINPROTO(update_runtime); BUILTINPROTO(update_app); BUILTINPROTO(uninstall_runtime); BUILTINPROTO(uninstall_app); +BUILTINPROTO(list_apps); +BUILTINPROTO(list_runtimes); #undef BUILTINPROTO diff --git a/app/xdg-app-main.c b/app/xdg-app-main.c index 4dffc448..8609e3e1 100644 --- a/app/xdg-app-main.c +++ b/app/xdg-app-main.c @@ -47,8 +47,7 @@ static XdgAppCommand commands[] = { { "install", xdg_app_builtin_install, "Install an application or runtime from a remote"}, { "update", xdg_app_builtin_update, "Update an installed application or runtime"}, { "uninstall", xdg_app_builtin_uninstall, "Uninstall an installed application or runtime" }, - { "list-runtimes", xdg_app_builtin_list_runtimes, "List installed runtimes" }, - { "list-apps", xdg_app_builtin_list_apps, "List installed applications" }, + { "list", xdg_app_builtin_list, "List installed apps and/or runtimes" }, { "\n Running applications" }, { "run", xdg_app_builtin_run, "Run an application" }, @@ -86,6 +85,8 @@ static XdgAppCommand commands[] = { { "modify-remote", xdg_app_builtin_modify_remote, NULL, TRUE }, { "ls-remote", xdg_app_builtin_ls_remote, NULL, TRUE }, { "list-remotes", xdg_app_builtin_list_remotes, NULL, TRUE }, + { "list-runtimes", xdg_app_builtin_list_runtimes, NULL, TRUE }, + { "list-apps", xdg_app_builtin_list_apps, NULL, TRUE }, { NULL } }; diff --git a/doc/Makefile.am b/doc/Makefile.am index c6d233cf..8954f035 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -27,8 +27,7 @@ man_MANS = \ xdg-app-install.1 \ xdg-app-update.1 \ xdg-app-uninstall.1 \ - xdg-app-list-runtimes.1 \ - xdg-app-list-apps.1 \ + xdg-app-list.1 \ xdg-app-make-current.1 \ xdg-app-run.1 \ xdg-app-override.1 \ diff --git a/doc/xdg-app-list-runtimes.xml b/doc/xdg-app-list-runtimes.xml deleted file mode 100644 index be4c1014..00000000 --- a/doc/xdg-app-list-runtimes.xml +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - xdg-app list-runtimes - xdg-app - - - - Developer - Alexander - Larsson - alexl@redhat.com - - - - - - xdg-app list-runtimes - 1 - - - - xdg-app-list-runtimes - List installed runtimes - - - - - xdg-app list-runtimes - OPTION - - - - - Description - - - Lists the names of the installed runtimes. - - - By default, both per-user and system-wide installations are shown. - Use the --user or --system options to change this. - - - - - - Options - - The following options are understood: - - - - - - - - Show help options and exit. - - - - - - - - Show per-user installations. - - - - - - - - Show system-wide installations. - - - - - - - - Show arches and branches, in addition to the runtime names. - - - - - - - - - Print debug information during command processing. - - - - - - - - Print version information and exit. - - - - - - - Examples - - - $ xdg-app --user list-runtimes --show-details - - -org.gnome.Platform.Var/x86_64/3.16 -org.gnome.Sdk.Var/x86_64/3.16 -org.gnome.Sdk/x86_64/3.14 -org.gnome.Sdk/x86_64/3.16 -org.gnome.Platform/x86_64/3.16 -org.gnome.Platform/x86_64/3.14 - - - - - - See also - - - xdg-app1, - xdg-app-install-runtime1, - xdg-app-update-runtime1 - - - - - - diff --git a/doc/xdg-app-list-apps.xml b/doc/xdg-app-list.xml similarity index 77% rename from doc/xdg-app-list-apps.xml rename to doc/xdg-app-list.xml index 071b94a7..001b0923 100644 --- a/doc/xdg-app-list-apps.xml +++ b/doc/xdg-app-list.xml @@ -2,10 +2,10 @@ - + - xdg-app list-apps + xdg-app list xdg-app @@ -19,18 +19,18 @@ - xdg-app list-apps + xdg-app list 1 - xdg-app-list-apps - List installed applications + xdg-app-list + List installed applications and/or runtimes - xdg-app list-apps + xdg-app list OPTION @@ -39,13 +39,17 @@ Description - Lists the names of the installed applications. + Lists the names of the installed applications and/or runtime. By default, both per-user and system-wide installations are shown. Use the --user or --system options to change this. + + By default this lists the installed apps, but you can + change this by using the --app or --runtime option. + @@ -88,6 +92,21 @@ + + + + + List applications. + + + + + + + + List runtimes. + + @@ -111,7 +130,7 @@ Examples - $ xdg-app --user list-apps + $ xdg-app --user list org.gnome.Builder