From 534fc303083f43025faa3a50b67a8f4d5e4a7d9c Mon Sep 17 00:00:00 2001 From: Ruixin Date: Fri, 11 Aug 2017 22:59:47 +0000 Subject: [PATCH] app: provide command description in a better place Before, when using rpm-ostree -h command, the command description was shown together with the command itself Now, we separate the command description out, providing user a better view of the description. Closes: #916 Approved by: jlebon --- src/app/main.c | 49 ++++++++++++++---------- src/app/rpmostree-builtin-cleanup.c | 2 +- src/app/rpmostree-builtin-container.c | 6 +-- src/app/rpmostree-builtin-deploy.c | 2 +- src/app/rpmostree-builtin-ex.c | 6 +-- src/app/rpmostree-builtin-initramfs.c | 2 +- src/app/rpmostree-builtin-livefs.c | 2 +- src/app/rpmostree-builtin-override.c | 2 +- src/app/rpmostree-builtin-rebase.c | 2 +- src/app/rpmostree-builtin-reload.c | 2 +- src/app/rpmostree-builtin-rollback.c | 2 +- src/app/rpmostree-builtin-status.c | 2 +- src/app/rpmostree-builtin-upgrade.c | 2 +- src/app/rpmostree-compose-builtin-tree.c | 2 +- src/app/rpmostree-db-builtin-diff.c | 2 +- src/app/rpmostree-db-builtin-list.c | 2 +- src/app/rpmostree-db-builtin-version.c | 2 +- src/app/rpmostree-override-builtins.c | 9 ++--- src/app/rpmostree-pkg-builtins.c | 4 +- 19 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/app/main.c b/src/app/main.c index 91cdbcd9..1e3e2aad 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -38,13 +38,15 @@ static RpmOstreeCommand commands[] = { #ifdef HAVE_COMPOSE_TOOLING { "compose", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, - NULL, rpmostree_builtin_compose }, + "Commands to compose a tree", + rpmostree_builtin_compose }, #endif { "cleanup", 0, "Clear cached/pending data", rpmostree_builtin_cleanup }, { "db", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, - NULL, rpmostree_builtin_db }, + "Commands to query the RPM database", + rpmostree_builtin_db }, { "deploy", RPM_OSTREE_BUILTIN_FLAG_SUPPORTS_PKG_INSTALLS, "Deploy a specific commit", rpmostree_builtin_deploy }, @@ -74,22 +76,20 @@ static RpmOstreeCommand commands[] = { rpmostree_builtin_uninstall }, /* Legacy aliases */ { "pkg-add", RPM_OSTREE_BUILTIN_FLAG_HIDDEN, - "Download and install layered RPM packages", - rpmostree_builtin_install }, + NULL, rpmostree_builtin_install }, { "pkg-remove", RPM_OSTREE_BUILTIN_FLAG_HIDDEN, - "Remove one or more overlay packages", - rpmostree_builtin_uninstall }, + NULL, rpmostree_builtin_uninstall }, { "rpm", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_HIDDEN, NULL, rpmostree_builtin_db }, /* Hidden */ { "ex", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_HIDDEN, - NULL,rpmostree_builtin_ex }, + "Commands still under experiment", rpmostree_builtin_ex }, { "start-daemon", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT | RPM_OSTREE_BUILTIN_FLAG_HIDDEN, - "start the daemon process", rpmostree_builtin_start_daemon }, + NULL, rpmostree_builtin_start_daemon }, { NULL } }; @@ -124,8 +124,14 @@ option_context_new_with_commands (RpmOstreeCommandInvocation *invocation, g_autoptr(GString) summary = g_string_new (NULL); if (invocation) - g_string_append_printf (summary, "Builtin \"%s\" Commands:", - invocation->command->name); + { + if (invocation->command->description != NULL) + g_string_append_printf (summary, "%s\n\n", + invocation->command->description); + + g_string_append_printf (summary, "Builtin \"%s\" Commands:", + invocation->command->name); + } else /* top level */ g_string_append (summary, "Builtin Commands:"); @@ -134,18 +140,9 @@ option_context_new_with_commands (RpmOstreeCommandInvocation *invocation, gboolean hidden = (command->flags & RPM_OSTREE_BUILTIN_FLAG_HIDDEN) > 0; if (!hidden) { - g_string_append_printf (summary, "\n %s", command->name); + g_string_append_printf (summary, "\n %-17s", command->name); if (command->description != NULL) - { - /* add padding for description alignment */ - guint max_command_len = 15; - guint pad = max_command_len - strlen (command->name); - - for (guint padding_num = 0; padding_num < pad + 2; padding_num++) - g_string_append (summary, " "); - - g_string_append_printf (summary, "%s", command->description); - } + g_string_append_printf (summary, "%s", command->description); } } @@ -171,6 +168,16 @@ rpmostree_option_context_parse (GOptionContext *context, invocation ? invocation->command->flags : RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD; gboolean use_daemon = ((flags & RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD) == 0); + if (invocation && invocation->command->description != NULL) + { + /* The extra summary explanation is only provided for commands with description */ + const char* context_summary = g_option_context_get_summary (context); + + /* check whether the summary has been set earlier */ + if (context_summary == NULL) + g_option_context_set_summary (context, invocation->command->description); + } + if (main_entries != NULL) g_option_context_add_main_entries (context, main_entries, NULL); diff --git a/src/app/rpmostree-builtin-cleanup.c b/src/app/rpmostree-builtin-cleanup.c index 9d5a41d9..c1166198 100644 --- a/src/app/rpmostree-builtin-cleanup.c +++ b/src/app/rpmostree-builtin-cleanup.c @@ -52,7 +52,7 @@ rpmostree_builtin_cleanup (int argc, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("- Clear cached/pending data"); + g_autoptr(GOptionContext) context = g_option_context_new (""); g_autoptr(GPtrArray) cleanup_types = g_ptr_array_new (); glnx_unref_object RPMOSTreeOS *os_proxy = NULL; glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; diff --git a/src/app/rpmostree-builtin-container.c b/src/app/rpmostree-builtin-container.c index eb479425..33399d78 100644 --- a/src/app/rpmostree-builtin-container.c +++ b/src/app/rpmostree-builtin-container.c @@ -25,12 +25,12 @@ static RpmOstreeCommand container_subcommands[] = { { "init", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, - NULL, rpmostree_container_builtin_init }, + "Initialize a local container", rpmostree_container_builtin_init }, { "assemble", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, - NULL, rpmostree_container_builtin_assemble }, + "Assemble a local container", rpmostree_container_builtin_assemble }, /* { "start", rpmostree_container_builtin_start }, */ { "upgrade", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, - NULL, rpmostree_container_builtin_upgrade }, + "Perform a local container upgrade", rpmostree_container_builtin_upgrade }, { NULL, 0, NULL, NULL } }; diff --git a/src/app/rpmostree-builtin-deploy.c b/src/app/rpmostree-builtin-deploy.c index 7212026f..37a311be 100644 --- a/src/app/rpmostree-builtin-deploy.c +++ b/src/app/rpmostree-builtin-deploy.c @@ -68,7 +68,7 @@ rpmostree_builtin_deploy (int argc, const char *const *install_pkgs = NULL; const char *const *uninstall_pkgs = NULL; - context = g_option_context_new ("REVISION - Deploy a specific commit"); + context = g_option_context_new ("REVISION"); if (!rpmostree_option_context_parse (context, option_entries, diff --git a/src/app/rpmostree-builtin-ex.c b/src/app/rpmostree-builtin-ex.c index 550c197e..7909b772 100644 --- a/src/app/rpmostree-builtin-ex.c +++ b/src/app/rpmostree-builtin-ex.c @@ -27,11 +27,11 @@ static RpmOstreeCommand ex_subcommands[] = { "Apply pending deployment changes to booted deployment", rpmostree_ex_builtin_livefs }, { "override", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, - NULL, rpmostree_ex_builtin_override }, + "Manage base overrides", rpmostree_ex_builtin_override }, { "unpack", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, - NULL, rpmostree_ex_builtin_unpack }, + "unpack RPM into local OSTree repo", rpmostree_ex_builtin_unpack }, { "container", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, - NULL, rpmostree_builtin_container }, + "Assemble local unprivileged containers", rpmostree_builtin_container }, { NULL, 0, NULL, NULL } }; diff --git a/src/app/rpmostree-builtin-initramfs.c b/src/app/rpmostree-builtin-initramfs.c index 9965ecba..347947b4 100644 --- a/src/app/rpmostree-builtin-initramfs.c +++ b/src/app/rpmostree-builtin-initramfs.c @@ -62,7 +62,7 @@ rpmostree_builtin_initramfs (int argc, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("- Enable or disable local initramfs regeneration"); + g_autoptr(GOptionContext) context = g_option_context_new (""); _cleanup_peer_ GPid peer_pid = 0; glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; diff --git a/src/app/rpmostree-builtin-livefs.c b/src/app/rpmostree-builtin-livefs.c index 06ec42e4..a2d831d6 100644 --- a/src/app/rpmostree-builtin-livefs.c +++ b/src/app/rpmostree-builtin-livefs.c @@ -59,7 +59,7 @@ rpmostree_ex_builtin_livefs (int argc, { _cleanup_peer_ GPid peer_pid = 0; glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; - g_autoptr(GOptionContext) context = g_option_context_new ("- Apply pending deployment changes to booted deployment"); + g_autoptr(GOptionContext) context = g_option_context_new (""); if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, diff --git a/src/app/rpmostree-builtin-override.c b/src/app/rpmostree-builtin-override.c index 32dab4e1..b9ce800a 100644 --- a/src/app/rpmostree-builtin-override.c +++ b/src/app/rpmostree-builtin-override.c @@ -25,7 +25,7 @@ static RpmOstreeCommand override_subcommands[] = { { "replace", RPM_OSTREE_BUILTIN_FLAG_SUPPORTS_PKG_INSTALLS, - "Remove packages from the base layer", + "Replace packages in the base layer", rpmostree_override_builtin_replace }, { "remove", RPM_OSTREE_BUILTIN_FLAG_SUPPORTS_PKG_INSTALLS, "Remove packages from the base layer", diff --git a/src/app/rpmostree-builtin-rebase.c b/src/app/rpmostree-builtin-rebase.c index 07f2c6a7..1e4dfa81 100644 --- a/src/app/rpmostree-builtin-rebase.c +++ b/src/app/rpmostree-builtin-rebase.c @@ -59,7 +59,7 @@ rpmostree_builtin_rebase (int argc, /* forced blank for now */ const char *packages[] = { NULL }; - g_autoptr(GOptionContext) context = g_option_context_new ("REFSPEC [REVISION] - Switch to a different tree"); + g_autoptr(GOptionContext) context = g_option_context_new ("REFSPEC [REVISION]"); glnx_unref_object RPMOSTreeOS *os_proxy = NULL; g_autofree char *transaction_address = NULL; glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; diff --git a/src/app/rpmostree-builtin-reload.c b/src/app/rpmostree-builtin-reload.c index 481db098..5de6d4c1 100644 --- a/src/app/rpmostree-builtin-reload.c +++ b/src/app/rpmostree-builtin-reload.c @@ -40,7 +40,7 @@ rpmostree_builtin_reload (int argc, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("- Reload configuration"); + g_autoptr(GOptionContext) context = g_option_context_new (""); glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; _cleanup_peer_ GPid peer_pid = 0; diff --git a/src/app/rpmostree-builtin-rollback.c b/src/app/rpmostree-builtin-rollback.c index c1f003ae..f18b8dbe 100644 --- a/src/app/rpmostree-builtin-rollback.c +++ b/src/app/rpmostree-builtin-rollback.c @@ -54,7 +54,7 @@ rpmostree_builtin_rollback (int argc, GCancellable *cancellable, GError **error) { - GOptionContext *context = g_option_context_new ("- Revert to the previously booted tree"); + GOptionContext *context = g_option_context_new (""); glnx_unref_object RPMOSTreeOS *os_proxy = NULL; glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; g_autofree char *transaction_address = NULL; diff --git a/src/app/rpmostree-builtin-status.c b/src/app/rpmostree-builtin-status.c index 78547341..b326f79e 100644 --- a/src/app/rpmostree-builtin-status.c +++ b/src/app/rpmostree-builtin-status.c @@ -585,7 +585,7 @@ rpmostree_builtin_status (int argc, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("- Get the version of the booted system"); + g_autoptr(GOptionContext) context = g_option_context_new (""); glnx_unref_object RPMOSTreeOS *os_proxy = NULL; glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; g_autoptr(GVariant) deployments = NULL; diff --git a/src/app/rpmostree-builtin-upgrade.c b/src/app/rpmostree-builtin-upgrade.c index 8bd2c76a..da9eb566 100644 --- a/src/app/rpmostree-builtin-upgrade.c +++ b/src/app/rpmostree-builtin-upgrade.c @@ -57,7 +57,7 @@ rpmostree_builtin_upgrade (int argc, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("- Perform a system upgrade"); + g_autoptr(GOptionContext) context = g_option_context_new (""); glnx_unref_object RPMOSTreeOS *os_proxy = NULL; glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; g_autoptr(GVariant) previous_default_deployment = NULL; diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index 57c42f3d..80566c31 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -984,7 +984,7 @@ rpmostree_compose_builtin_tree (int argc, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("TREEFILE - Install packages and commit the result to an OSTree repository"); + g_autoptr(GOptionContext) context = g_option_context_new ("TREEFILE"); if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, diff --git a/src/app/rpmostree-db-builtin-diff.c b/src/app/rpmostree-db-builtin-diff.c index 82506fa8..79b5f01b 100644 --- a/src/app/rpmostree-db-builtin-diff.c +++ b/src/app/rpmostree-db-builtin-diff.c @@ -39,7 +39,7 @@ rpmostree_db_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = - g_option_context_new ("COMMIT COMMIT - Show package changes between two commits"); + g_option_context_new ("COMMIT COMMIT"); g_autoptr(OstreeRepo) repo = NULL; if (!rpmostree_db_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, diff --git a/src/app/rpmostree-db-builtin-list.c b/src/app/rpmostree-db-builtin-list.c index 62da50d2..d630e38a 100644 --- a/src/app/rpmostree-db-builtin-list.c +++ b/src/app/rpmostree-db-builtin-list.c @@ -84,7 +84,7 @@ rpmostree_db_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = - g_option_context_new ("[PREFIX-PKGNAME...] COMMIT... - List packages within commits"); + g_option_context_new ("[PREFIX-PKGNAME...] COMMIT..."); g_autoptr(OstreeRepo) repo = NULL; if (!rpmostree_db_option_context_parse (context, option_entries, &argc, &argv, diff --git a/src/app/rpmostree-db-builtin-version.c b/src/app/rpmostree-db-builtin-version.c index 8887289f..63b48cb2 100644 --- a/src/app/rpmostree-db-builtin-version.c +++ b/src/app/rpmostree-db-builtin-version.c @@ -89,7 +89,7 @@ rpmostree_db_builtin_version (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = - g_option_context_new ("COMMIT... - Show rpmdb version of packages within the commits"); + g_option_context_new ("COMMIT..."); g_autoptr(OstreeRepo) repo = NULL; if (!rpmostree_db_option_context_parse (context, db_version_entries, &argc, diff --git a/src/app/rpmostree-override-builtins.c b/src/app/rpmostree-override-builtins.c index bd534426..a94d342c 100644 --- a/src/app/rpmostree-override-builtins.c +++ b/src/app/rpmostree-override-builtins.c @@ -114,8 +114,7 @@ rpmostree_override_builtin_replace (int argc, char **argv, glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; _cleanup_peer_ GPid peer_pid = 0; - context = g_option_context_new ("PACKAGE [PACKAGE...] - " - "Remove packages from the base layer"); + context = g_option_context_new ("PACKAGE [PACKAGE...]"); if (!rpmostree_option_context_parse (context, option_entries, @@ -156,8 +155,7 @@ rpmostree_override_builtin_remove (int argc, char **argv, glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; _cleanup_peer_ GPid peer_pid = 0; - context = g_option_context_new ("PACKAGE [PACKAGE...] - " - "Remove packages from the base layer"); + context = g_option_context_new ("PACKAGE [PACKAGE...]"); if (!rpmostree_option_context_parse (context, option_entries, @@ -198,8 +196,7 @@ rpmostree_override_builtin_reset (int argc, char **argv, glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; _cleanup_peer_ GPid peer_pid = 0; - context = g_option_context_new ("PACKAGE [PACKAGE...] - " - "Reset currently active package overrides"); + context = g_option_context_new ("PACKAGE [PACKAGE...]"); g_option_context_add_main_entries (context, reset_option_entries, NULL); diff --git a/src/app/rpmostree-pkg-builtins.c b/src/app/rpmostree-pkg-builtins.c index 476edc51..468d86d8 100644 --- a/src/app/rpmostree-pkg-builtins.c +++ b/src/app/rpmostree-pkg-builtins.c @@ -154,7 +154,7 @@ rpmostree_builtin_install (int argc, glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; _cleanup_peer_ GPid peer_pid = 0; - context = g_option_context_new ("PACKAGE [PACKAGE...] - Download and install layered RPM packages"); + context = g_option_context_new ("PACKAGE [PACKAGE...]"); g_option_context_add_main_entries (context, uninstall_option_entry, NULL); @@ -197,7 +197,7 @@ rpmostree_builtin_uninstall (int argc, glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; _cleanup_peer_ GPid peer_pid = 0; - context = g_option_context_new ("PACKAGE [PACKAGE...] - Remove one or more overlay packages"); + context = g_option_context_new ("PACKAGE [PACKAGE...]"); g_option_context_add_main_entries (context, install_option_entry, NULL);