ostree: Describe subcommands in help output

Added a description argument to all type
of commands. Now when we include -h or --help
for commands that contain subcommands, the description
for those subcommands are shown.

The added subcommands help will be provided to the following commands:
- ostree -h
- ostree admin -h
- ostree admin instutil -h
- ostree remote -h
- ostree static-delta -h

Closes: #1267
Approved by: cgwalters
This commit is contained in:
Ruixin Bao 2017-10-13 16:15:13 +00:00 committed by Atomic Bot
parent 2531d8fe63
commit 3c360a720f
9 changed files with 140 additions and 67 deletions

View File

@ -32,37 +32,63 @@
#include "ot-builtins.h" #include "ot-builtins.h"
static OstreeCommand commands[] = { static OstreeCommand commands[] = {
{ "admin", ostree_builtin_admin }, { "admin", ostree_builtin_admin ,
{ "cat", ostree_builtin_cat }, "Commands that needs admin privilege" },
{ "checkout", ostree_builtin_checkout }, { "cat", ostree_builtin_cat,
{ "checksum", ostree_builtin_checksum }, "Concatenate contents of files"},
{ "commit", ostree_builtin_commit }, { "checkout", ostree_builtin_checkout,
{ "config", ostree_builtin_config }, "Check out a commit into a filesystem tree" },
{ "diff", ostree_builtin_diff }, { "checksum", ostree_builtin_checksum,
{ "export", ostree_builtin_export }, "Checksum a file or directory" },
{ "commit", ostree_builtin_commit,
"Commit a new revision" },
{ "config", ostree_builtin_config,
"Change repo configuration settings" },
{ "diff", ostree_builtin_diff,
"Compare directory TARGETDIR against revision REV"},
{ "export", ostree_builtin_export,
"Stream COMMIT to stdout in tar format" },
#ifdef OSTREE_ENABLE_EXPERIMENTAL_API #ifdef OSTREE_ENABLE_EXPERIMENTAL_API
{ "find-remotes", ostree_builtin_find_remotes }, { "find-remotes", ostree_builtin_find_remotes,
{ "create-usb", ostree_builtin_create_usb }, "Find remotes to serve the given refs" },
{ "create-usb", ostree_builtin_create_usb,
"Copy the refs to a USB stick" },
#endif #endif
{ "fsck", ostree_builtin_fsck }, { "fsck", ostree_builtin_fsck,
{ "gpg-sign", ostree_builtin_gpg_sign }, "Check the repository for consistency" },
{ "init", ostree_builtin_init }, { "gpg-sign", ostree_builtin_gpg_sign,
{ "log", ostree_builtin_log }, "Sign a commit" },
{ "ls", ostree_builtin_ls }, { "init", ostree_builtin_init,
{ "prune", ostree_builtin_prune }, "Initialize a new empty repository" },
{ "pull-local", ostree_builtin_pull_local }, { "log", ostree_builtin_log,
"Show log starting at commit or ref" },
{ "ls", ostree_builtin_ls,
"List file paths" },
{ "prune", ostree_builtin_prune,
"Search for unreachable objects" },
{ "pull-local", ostree_builtin_pull_local,
"Copy data from SRC_REPO" },
#ifdef HAVE_LIBCURL_OR_LIBSOUP #ifdef HAVE_LIBCURL_OR_LIBSOUP
{ "pull", ostree_builtin_pull }, { "pull", ostree_builtin_pull,
"Download data from remote repository" },
#endif #endif
{ "refs", ostree_builtin_refs }, { "refs", ostree_builtin_refs,
{ "remote", ostree_builtin_remote }, "List refs" },
{ "reset", ostree_builtin_reset }, { "remote", ostree_builtin_remote,
{ "rev-parse", ostree_builtin_rev_parse }, "Remote commands that may involve internet access" },
{ "show", ostree_builtin_show }, { "reset", ostree_builtin_reset,
{ "static-delta", ostree_builtin_static_delta }, "Reset a REF to a previous COMMIT" },
{ "summary", ostree_builtin_summary }, { "rev-parse", ostree_builtin_rev_parse,
"Output the target of a rev" },
{ "show", ostree_builtin_show,
"Output a metadata object" },
{ "static-delta", ostree_builtin_static_delta,
"Static delta related commands" },
{ "summary", ostree_builtin_summary,
"Manage summary metadata" },
#if defined(HAVE_LIBSOUP) && defined(BUILDOPT_ENABLE_TRIVIAL_HTTPD_CMDLINE) #if defined(HAVE_LIBSOUP) && defined(BUILDOPT_ENABLE_TRIVIAL_HTTPD_CMDLINE)
{ "trivial-httpd", ostree_builtin_trivial_httpd }, { "trivial-httpd", ostree_builtin_trivial_httpd,
NULL },
#endif #endif
{ NULL } { NULL }
}; };

View File

@ -31,15 +31,19 @@
typedef struct { typedef struct {
const char *name; const char *name;
gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error);
const char *description;
} OstreeAdminInstUtilCommand; } OstreeAdminInstUtilCommand;
static OstreeAdminInstUtilCommand admin_instutil_subcommands[] = { static OstreeAdminInstUtilCommand admin_instutil_subcommands[] = {
#ifdef HAVE_SELINUX #ifdef HAVE_SELINUX
{ "selinux-ensure-labeled", ot_admin_instutil_builtin_selinux_ensure_labeled }, { "selinux-ensure-labeled", ot_admin_instutil_builtin_selinux_ensure_labeled,
"Relabel all or part of a deployment" },
#endif #endif
{ "set-kargs", ot_admin_instutil_builtin_set_kargs }, { "set-kargs", ot_admin_instutil_builtin_set_kargs,
{ "grub2-generate", ot_admin_instutil_builtin_grub2_generate }, "Set new kernel command line arguments(Not stable)" },
{ NULL, NULL } { "grub2-generate", ot_admin_instutil_builtin_grub2_generate,
"Generate GRUB2 configuration from given BLS entries" },
{ NULL, NULL, NULL }
}; };
static GOptionContext * static GOptionContext *
@ -52,7 +56,10 @@ ostree_admin_instutil_option_context_new_with_commands (void)
while (command->name != NULL) while (command->name != NULL)
{ {
g_string_append_printf (summary, "\n %s", command->name); g_string_append_printf (summary, "\n %-24s", command->name);
if (command->description != NULL)
g_string_append_printf (summary, "%s", command->description);
command++; command++;
} }

View File

@ -33,22 +33,35 @@
typedef struct { typedef struct {
const char *name; const char *name;
gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error);
const char *description;
} OstreeAdminCommand; } OstreeAdminCommand;
static OstreeAdminCommand admin_subcommands[] = { static OstreeAdminCommand admin_subcommands[] = {
{ "cleanup", ot_admin_builtin_cleanup }, { "cleanup", ot_admin_builtin_cleanup,
{ "config-diff", ot_admin_builtin_diff }, "Delete untagged deployments and repository objects" },
{ "deploy", ot_admin_builtin_deploy }, { "config-diff", ot_admin_builtin_diff,
{ "init-fs", ot_admin_builtin_init_fs }, "Diff current /etc configuration versus default" },
{ "instutil", ot_admin_builtin_instutil }, { "deploy", ot_admin_builtin_deploy,
{ "os-init", ot_admin_builtin_os_init }, "Checkout revision REFSPEC as the new default deployment" },
{ "set-origin", ot_admin_builtin_set_origin }, { "init-fs", ot_admin_builtin_init_fs,
{ "status", ot_admin_builtin_status }, "Initialize a root filesystem" },
{ "switch", ot_admin_builtin_switch }, { "instutil", ot_admin_builtin_instutil,
{ "undeploy", ot_admin_builtin_undeploy }, "Provide instutil commands, allow admin to change boot configuration and relabel selinux " },
{ "unlock", ot_admin_builtin_unlock }, { "os-init", ot_admin_builtin_os_init,
{ "upgrade", ot_admin_builtin_upgrade }, "Initialize empty state for given operating system" },
{ NULL, NULL } { "set-origin", ot_admin_builtin_set_origin,
"Set Origin and create a new origin file" },
{ "status", ot_admin_builtin_status,
"List deployments" },
{ "switch", ot_admin_builtin_switch,
"Construct new tree from REF and deploy it" },
{ "undeploy", ot_admin_builtin_undeploy,
"Delete deployment INDEX" },
{ "unlock", ot_admin_builtin_unlock,
"Make the current deployment mutable (as a hotfix or development)" },
{ "upgrade", ot_admin_builtin_upgrade,
"Construct new tree from current origin and deploy it, if it changed" },
{ NULL, NULL, NULL }
}; };
static GOptionContext * static GOptionContext *
@ -61,7 +74,9 @@ ostree_admin_option_context_new_with_commands (void)
while (command->name != NULL) while (command->name != NULL)
{ {
g_string_append_printf (summary, "\n %s", command->name); g_string_append_printf (summary, "\n %-19s", command->name);
if (command->description != NULL)
g_string_append_printf (summary, "%s", command->description);
command++; command++;
} }

View File

@ -28,22 +28,33 @@
typedef struct { typedef struct {
const char *name; const char *name;
gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error);
const char *description;
} OstreeRemoteCommand; } OstreeRemoteCommand;
static OstreeRemoteCommand remote_subcommands[] = { static OstreeRemoteCommand remote_subcommands[] = {
{ "add", ot_remote_builtin_add }, { "add", ot_remote_builtin_add,
{ "delete", ot_remote_builtin_delete }, "Add a remote repository" },
{ "show-url", ot_remote_builtin_show_url }, { "delete", ot_remote_builtin_delete,
{ "list", ot_remote_builtin_list }, "Delete a remote repository" },
{ "gpg-import", ot_remote_builtin_gpg_import }, { "show-url", ot_remote_builtin_show_url,
"Show remote repository URL" },
{ "list", ot_remote_builtin_list,
"List remote repository names" },
{ "gpg-import", ot_remote_builtin_gpg_import,
"Import GPG keys" },
#ifdef HAVE_LIBSOUP #ifdef HAVE_LIBSOUP
{ "add-cookie", ot_remote_builtin_add_cookie }, { "add-cookie", ot_remote_builtin_add_cookie,
{ "delete-cookie", ot_remote_builtin_delete_cookie }, "Add a cookie to remote" },
{ "list-cookies", ot_remote_builtin_list_cookies }, { "delete-cookie", ot_remote_builtin_delete_cookie,
"Remove one cookie from remote" },
{ "list-cookies", ot_remote_builtin_list_cookies,
"Show remote repository cookies" },
#endif #endif
{ "refs", ot_remote_builtin_refs }, { "refs", ot_remote_builtin_refs,
{ "summary", ot_remote_builtin_summary }, "List remote refs" },
{ NULL, NULL } { "summary", ot_remote_builtin_summary,
"Show remote summary" },
{ NULL, NULL, NULL }
}; };
static GOptionContext * static GOptionContext *
@ -56,7 +67,10 @@ remote_option_context_new_with_commands (void)
while (subcommand->name != NULL) while (subcommand->name != NULL)
{ {
g_string_append_printf (summary, "\n %s", subcommand->name); g_string_append_printf (summary, "\n %-18s", subcommand->name);
if (subcommand->description != NULL)
g_string_append_printf (summary, "%s", subcommand->description);
subcommand++; subcommand++;
} }

View File

@ -50,12 +50,17 @@ BUILTINPROTO(apply_offline);
#undef BUILTINPROTO #undef BUILTINPROTO
static OstreeCommand static_delta_subcommands[] = { static OstreeCommand static_delta_subcommands[] = {
{ "list", ot_static_delta_builtin_list }, { "list", ot_static_delta_builtin_list,
{ "show", ot_static_delta_builtin_show }, "List static delta files" },
{ "delete", ot_static_delta_builtin_delete }, { "show", ot_static_delta_builtin_show,
{ "generate", ot_static_delta_builtin_generate }, "Dump information on a delta" },
{ "apply-offline", ot_static_delta_builtin_apply_offline }, { "delete", ot_static_delta_builtin_delete,
{ NULL, NULL } "Remove a delta" },
{ "generate", ot_static_delta_builtin_generate,
"Generate static delta files" },
{ "apply-offline", ot_static_delta_builtin_apply_offline,
"Apply static delta file" },
{ NULL, NULL, NULL }
}; };
/* ATTENTION: /* ATTENTION:
@ -105,7 +110,7 @@ static_delta_usage (char **argv,
while (command->name) while (command->name)
{ {
print_func (" %s\n", command->name); print_func (" %-17s%s\n", command->name, command->description ?: "");
command++; command++;
} }

View File

@ -64,7 +64,11 @@ ostree_option_context_new_with_commands (OstreeCommand *commands)
while (commands->name != NULL) while (commands->name != NULL)
{ {
g_string_append_printf (summary, "\n %s", commands->name); g_string_append_printf (summary, "\n %-18s", commands->name);
if (commands->description != NULL )
g_string_append_printf (summary, "%s", commands->description);
commands++; commands++;
} }

View File

@ -40,6 +40,7 @@ typedef enum {
typedef struct { typedef struct {
const char *name; const char *name;
gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error);
const char *description;
} OstreeCommand; } OstreeCommand;
int ostree_run (int argc, char **argv, OstreeCommand *commands, GError **error); int ostree_run (int argc, char **argv, OstreeCommand *commands, GError **error);

View File

@ -41,7 +41,7 @@ gboolean
ot_remote_builtin_delete_cookie (int argc, char **argv, GCancellable *cancellable, GError **error) ot_remote_builtin_delete_cookie (int argc, char **argv, GCancellable *cancellable, GError **error)
{ {
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
g_autoptr(GOptionContext) context = g_option_context_new ("NAME DOMAIN PATH COOKIE_NAME- Remote one cookie from remote"); g_autoptr(GOptionContext) context = g_option_context_new ("NAME DOMAIN PATH COOKIE_NAME- Remove one cookie from remote");
if (!ostree_option_context_parse (context, option_entries, &argc, &argv, if (!ostree_option_context_parse (context, option_entries, &argc, &argv,
OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))

View File

@ -46,7 +46,8 @@ test_recursive() {
test_usage_output out "$cmd" test_usage_output out "$cmd"
assert_file_empty err assert_file_empty err
builtins=`sed -n '/^Builtin \("[^"]*" \)\?Commands:$/,/^$/p' <out | tail -n +2` # Select the list of commands, for each line, remove the leading spaces, and take the first word(command) of each line
builtins=`sed -n '/^Builtin \("[^"]*" \)\?Commands:$/,/^$/p' <out | tail -n +2 | sed -e 's/^[[:space:]]*//' | cut -d " " -f1`
if [ "$builtins" != "" ] ; then if [ "$builtins" != "" ] ; then
found_subcommands=1 found_subcommands=1