apk: usage: cleanup help text when no applet is selected

cute-signatures
William Pitcock 2018-01-09 01:47:21 +00:00
parent 118f29c895
commit abf7c2838b
16 changed files with 52 additions and 13 deletions

View File

@ -171,6 +171,7 @@ static struct apk_applet apk_add = {
"them, while ensuring that all dependencies are met",
.arguments = "PACKAGE...",
.open_flags = APK_OPENF_WRITE,
.command_groups = APK_COMMAND_GROUP_INSTALL,
.context_size = sizeof(struct add_ctx),
.optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet },
.main = add_main,

View File

@ -338,6 +338,23 @@ static void print_options(int num_opts, const struct apk_option *opts)
}
}
static void print_applets(const char *desc, unsigned int group)
{
struct apk_applet *a;
printf("\n%s\n", desc);
foreach_applet(a) {
if (group && (a->command_groups & group) != group)
continue;
struct apk_indent indent = { .indent = 12 };
indent.x = printf(" %-*s", indent.indent - 3, a->name);
apk_print_indented_words(&indent, a->help);
printf("\n");
}
}
static int usage(struct apk_applet *applet)
{
const struct apk_option_group **optgroups = default_optgroups;
@ -345,16 +362,17 @@ static int usage(struct apk_applet *applet)
version();
if (applet == NULL) {
struct apk_applet *a;
if (apk_verbosity > 1) {
print_usage("COMMAND", "[ARGS]...", default_optgroups);
print_applets("The following commands are available:", 0);
} else {
print_applets("Installing and removing packages:", APK_COMMAND_GROUP_INSTALL);
print_applets("System maintenance:", APK_COMMAND_GROUP_SYSTEM);
print_applets("Querying information about packages:", APK_COMMAND_GROUP_QUERY);
print_applets("Repository maintenance:", APK_COMMAND_GROUP_REPO);
print_usage("COMMAND", "[ARGS]...", default_optgroups);
printf("\nThe following commands are available:\n");
foreach_applet(a) {
struct apk_indent indent = { .indent = 12 };
indent.x = printf(" %-*s", indent.indent - 3, a->name);
apk_print_indented_words(&indent, a->help);
printf("\n");
printf("\nUse apk <command> --help for command-specific help.\n");
printf("Use apk --help --verbose for a full command listing.\n");
}
} else {
struct apk_indent indent = { .indent = 2 };
@ -366,9 +384,11 @@ static int usage(struct apk_applet *applet)
printf("\n");
}
for (i = 0; optgroups[i]; i++) {
printf("\n%s options:\n", optgroups[i]->name);
print_options(optgroups[i]->num_options, optgroups[i]->options);
if (applet != NULL || apk_verbosity > 1) {
for (i = 0; optgroups[i]; i++) {
printf("\n%s options:\n", optgroups[i]->name);
print_options(optgroups[i]->num_options, optgroups[i]->options);
}
}
printf("\nThis apk has coffee making abilities.\n");

View File

@ -17,6 +17,11 @@
#include "apk_defines.h"
#include "apk_database.h"
#define APK_COMMAND_GROUP_INSTALL 0x0001
#define APK_COMMAND_GROUP_SYSTEM 0x0002
#define APK_COMMAND_GROUP_QUERY 0x0004
#define APK_COMMAND_GROUP_REPO 0x0008
struct apk_option {
int val;
const char *name;
@ -42,7 +47,7 @@ struct apk_applet {
const char *help;
const struct apk_option_group *optgroups[4];
unsigned int open_flags, forced_flags, forced_force;
unsigned int open_flags, forced_flags, forced_force, command_groups;
int context_size;
int (*main)(void *ctx, struct apk_database *db, struct apk_string_array *args);

View File

@ -152,6 +152,7 @@ static struct apk_applet apk_cache = {
"unneeded files from cache",
.arguments = "sync | clean | download",
.open_flags = APK_OPENF_READ|APK_OPENF_NO_SCRIPTS|APK_OPENF_CACHE_WRITE,
.command_groups = APK_COMMAND_GROUP_SYSTEM,
.main = cache_main,
};

View File

@ -162,6 +162,7 @@ static struct apk_applet apk_del = {
.help = "Remove PACKAGEs from 'world' and uninstall them",
.arguments = "PACKAGE...",
.open_flags = APK_OPENF_WRITE,
.command_groups = APK_COMMAND_GROUP_INSTALL,
.context_size = sizeof(struct del_ctx),
.optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet },
.main = del_main,

View File

@ -172,6 +172,7 @@ static struct apk_applet apk_dot = {
.help = "Generate graphviz graphs",
.arguments = "PKGMASK...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.command_groups = APK_COMMAND_GROUP_QUERY,
.context_size = sizeof(struct dot_ctx),
.optgroups = { &optgroup_global, &optgroup_applet },
.main = dot_main,

View File

@ -349,6 +349,7 @@ static struct apk_applet apk_fetch = {
.help = "Download PACKAGEs from global repositories to a local directory",
.arguments = "PACKAGE...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.command_groups = APK_COMMAND_GROUP_REPO,
.context_size = sizeof(struct fetch_ctx),
.optgroups = { &optgroup_global, &optgroup_applet },
.main = fetch_main,

View File

@ -119,6 +119,7 @@ static struct apk_applet apk_fix = {
"dependencies",
.arguments = "PACKAGE...",
.open_flags = APK_OPENF_WRITE,
.command_groups = APK_COMMAND_GROUP_SYSTEM,
.context_size = sizeof(struct fix_ctx),
.optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet },
.main = fix_main,

View File

@ -262,6 +262,7 @@ static struct apk_applet apk_index = {
.help = "Create repository index file from FILEs",
.arguments = "FILE...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS,
.command_groups = APK_COMMAND_GROUP_REPO,
.context_size = sizeof(struct index_ctx),
.optgroups = { &optgroup_global, &optgroup_applet },
.main = index_main,

View File

@ -475,6 +475,7 @@ static struct apk_applet apk_info = {
.help = "Give detailed information about PACKAGEs or repositories",
.arguments = "PACKAGE...",
.open_flags = APK_OPENF_READ,
.command_groups = APK_COMMAND_GROUP_QUERY,
.context_size = sizeof(struct info_ctx),
.optgroups = { &optgroup_global, &optgroup_applet },
.main = info_main,

View File

@ -128,6 +128,7 @@ static struct apk_applet apk_manifest = {
.help = "Show checksums of package contents",
.arguments = "PACKAGE...",
.open_flags = APK_OPENF_READ,
.command_groups = APK_COMMAND_GROUP_REPO,
.main = manifest_main,
};

View File

@ -72,6 +72,7 @@ static struct apk_applet apk_policy = {
.name = "policy",
.help = "Show repository policy for packages",
.open_flags = APK_OPENF_READ,
.command_groups = APK_COMMAND_GROUP_QUERY,
.main = policy_main,
};

View File

@ -209,6 +209,7 @@ static struct apk_applet apk_search = {
.help = "Search package by PATTERNs or by indexed dependencies",
.arguments = "PATTERN",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.command_groups = APK_COMMAND_GROUP_QUERY,
.context_size = sizeof(struct search_ctx),
.optgroups = { &optgroup_global, &optgroup_applet },
.main = search_main,

View File

@ -50,6 +50,7 @@ static struct apk_applet apk_update = {
.help = "Update repository indexes from all remote repositories",
.open_flags = APK_OPENF_WRITE,
.forced_force = APK_FORCE_REFRESH,
.command_groups = APK_COMMAND_GROUP_SYSTEM,
.main = update_main,
};

View File

@ -182,6 +182,7 @@ static struct apk_applet apk_upgrade = {
.name = "upgrade",
.help = "Upgrade currently installed packages to match repositories",
.open_flags = APK_OPENF_WRITE,
.command_groups = APK_COMMAND_GROUP_SYSTEM,
.context_size = sizeof(struct upgrade_ctx),
.optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet },
.main = upgrade_main,

View File

@ -59,6 +59,7 @@ static struct apk_applet apk_verify = {
.help = "Verify package integrity and signature",
.arguments = "FILE...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.command_groups = APK_COMMAND_GROUP_REPO,
.forced_flags = APK_ALLOW_UNTRUSTED,
.main = verify_main,
};