Commit abf7c283 authored by Ariadne Conill's avatar Ariadne Conill

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

parent 118f29c8
...@@ -171,6 +171,7 @@ static struct apk_applet apk_add = { ...@@ -171,6 +171,7 @@ static struct apk_applet apk_add = {
"them, while ensuring that all dependencies are met", "them, while ensuring that all dependencies are met",
.arguments = "PACKAGE...", .arguments = "PACKAGE...",
.open_flags = APK_OPENF_WRITE, .open_flags = APK_OPENF_WRITE,
.command_groups = APK_COMMAND_GROUP_INSTALL,
.context_size = sizeof(struct add_ctx), .context_size = sizeof(struct add_ctx),
.optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet },
.main = add_main, .main = add_main,
......
...@@ -338,6 +338,23 @@ static void print_options(int num_opts, const struct apk_option *opts) ...@@ -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) static int usage(struct apk_applet *applet)
{ {
const struct apk_option_group **optgroups = default_optgroups; const struct apk_option_group **optgroups = default_optgroups;
...@@ -345,16 +362,17 @@ static int usage(struct apk_applet *applet) ...@@ -345,16 +362,17 @@ static int usage(struct apk_applet *applet)
version(); version();
if (applet == NULL) { if (applet == NULL) {
struct apk_applet *a; if (apk_verbosity > 1) {
print_usage("COMMAND", "[ARGS]...", default_optgroups);
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);
printf("\nThe following commands are available:\n"); printf("\nUse apk <command> --help for command-specific help.\n");
foreach_applet(a) { printf("Use apk --help --verbose for a full command listing.\n");
struct apk_indent indent = { .indent = 12 };
indent.x = printf(" %-*s", indent.indent - 3, a->name);
apk_print_indented_words(&indent, a->help);
printf("\n");
} }
} else { } else {
struct apk_indent indent = { .indent = 2 }; struct apk_indent indent = { .indent = 2 };
...@@ -366,9 +384,11 @@ static int usage(struct apk_applet *applet) ...@@ -366,9 +384,11 @@ static int usage(struct apk_applet *applet)
printf("\n"); printf("\n");
} }
for (i = 0; optgroups[i]; i++) { if (applet != NULL || apk_verbosity > 1) {
printf("\n%s options:\n", optgroups[i]->name); for (i = 0; optgroups[i]; i++) {
print_options(optgroups[i]->num_options, optgroups[i]->options); 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"); printf("\nThis apk has coffee making abilities.\n");
......
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
#include "apk_defines.h" #include "apk_defines.h"
#include "apk_database.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 { struct apk_option {
int val; int val;
const char *name; const char *name;
...@@ -42,7 +47,7 @@ struct apk_applet { ...@@ -42,7 +47,7 @@ struct apk_applet {
const char *help; const char *help;
const struct apk_option_group *optgroups[4]; 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 context_size;
int (*main)(void *ctx, struct apk_database *db, struct apk_string_array *args); int (*main)(void *ctx, struct apk_database *db, struct apk_string_array *args);
......
...@@ -152,6 +152,7 @@ static struct apk_applet apk_cache = { ...@@ -152,6 +152,7 @@ static struct apk_applet apk_cache = {
"unneeded files from cache", "unneeded files from cache",
.arguments = "sync | clean | download", .arguments = "sync | clean | download",
.open_flags = APK_OPENF_READ|APK_OPENF_NO_SCRIPTS|APK_OPENF_CACHE_WRITE, .open_flags = APK_OPENF_READ|APK_OPENF_NO_SCRIPTS|APK_OPENF_CACHE_WRITE,
.command_groups = APK_COMMAND_GROUP_SYSTEM,
.main = cache_main, .main = cache_main,
}; };
......
...@@ -162,6 +162,7 @@ static struct apk_applet apk_del = { ...@@ -162,6 +162,7 @@ static struct apk_applet apk_del = {
.help = "Remove PACKAGEs from 'world' and uninstall them", .help = "Remove PACKAGEs from 'world' and uninstall them",
.arguments = "PACKAGE...", .arguments = "PACKAGE...",
.open_flags = APK_OPENF_WRITE, .open_flags = APK_OPENF_WRITE,
.command_groups = APK_COMMAND_GROUP_INSTALL,
.context_size = sizeof(struct del_ctx), .context_size = sizeof(struct del_ctx),
.optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet },
.main = del_main, .main = del_main,
......
...@@ -172,6 +172,7 @@ static struct apk_applet apk_dot = { ...@@ -172,6 +172,7 @@ static struct apk_applet apk_dot = {
.help = "Generate graphviz graphs", .help = "Generate graphviz graphs",
.arguments = "PKGMASK...", .arguments = "PKGMASK...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE, .open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.command_groups = APK_COMMAND_GROUP_QUERY,
.context_size = sizeof(struct dot_ctx), .context_size = sizeof(struct dot_ctx),
.optgroups = { &optgroup_global, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_applet },
.main = dot_main, .main = dot_main,
......
...@@ -349,6 +349,7 @@ static struct apk_applet apk_fetch = { ...@@ -349,6 +349,7 @@ static struct apk_applet apk_fetch = {
.help = "Download PACKAGEs from global repositories to a local directory", .help = "Download PACKAGEs from global repositories to a local directory",
.arguments = "PACKAGE...", .arguments = "PACKAGE...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE, .open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.command_groups = APK_COMMAND_GROUP_REPO,
.context_size = sizeof(struct fetch_ctx), .context_size = sizeof(struct fetch_ctx),
.optgroups = { &optgroup_global, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_applet },
.main = fetch_main, .main = fetch_main,
......
...@@ -119,6 +119,7 @@ static struct apk_applet apk_fix = { ...@@ -119,6 +119,7 @@ static struct apk_applet apk_fix = {
"dependencies", "dependencies",
.arguments = "PACKAGE...", .arguments = "PACKAGE...",
.open_flags = APK_OPENF_WRITE, .open_flags = APK_OPENF_WRITE,
.command_groups = APK_COMMAND_GROUP_SYSTEM,
.context_size = sizeof(struct fix_ctx), .context_size = sizeof(struct fix_ctx),
.optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet },
.main = fix_main, .main = fix_main,
......
...@@ -262,6 +262,7 @@ static struct apk_applet apk_index = { ...@@ -262,6 +262,7 @@ static struct apk_applet apk_index = {
.help = "Create repository index file from FILEs", .help = "Create repository index file from FILEs",
.arguments = "FILE...", .arguments = "FILE...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS, .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), .context_size = sizeof(struct index_ctx),
.optgroups = { &optgroup_global, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_applet },
.main = index_main, .main = index_main,
......
...@@ -475,6 +475,7 @@ static struct apk_applet apk_info = { ...@@ -475,6 +475,7 @@ static struct apk_applet apk_info = {
.help = "Give detailed information about PACKAGEs or repositories", .help = "Give detailed information about PACKAGEs or repositories",
.arguments = "PACKAGE...", .arguments = "PACKAGE...",
.open_flags = APK_OPENF_READ, .open_flags = APK_OPENF_READ,
.command_groups = APK_COMMAND_GROUP_QUERY,
.context_size = sizeof(struct info_ctx), .context_size = sizeof(struct info_ctx),
.optgroups = { &optgroup_global, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_applet },
.main = info_main, .main = info_main,
......
...@@ -128,6 +128,7 @@ static struct apk_applet apk_manifest = { ...@@ -128,6 +128,7 @@ static struct apk_applet apk_manifest = {
.help = "Show checksums of package contents", .help = "Show checksums of package contents",
.arguments = "PACKAGE...", .arguments = "PACKAGE...",
.open_flags = APK_OPENF_READ, .open_flags = APK_OPENF_READ,
.command_groups = APK_COMMAND_GROUP_REPO,
.main = manifest_main, .main = manifest_main,
}; };
......
...@@ -72,6 +72,7 @@ static struct apk_applet apk_policy = { ...@@ -72,6 +72,7 @@ static struct apk_applet apk_policy = {
.name = "policy", .name = "policy",
.help = "Show repository policy for packages", .help = "Show repository policy for packages",
.open_flags = APK_OPENF_READ, .open_flags = APK_OPENF_READ,
.command_groups = APK_COMMAND_GROUP_QUERY,
.main = policy_main, .main = policy_main,
}; };
......
...@@ -209,6 +209,7 @@ static struct apk_applet apk_search = { ...@@ -209,6 +209,7 @@ static struct apk_applet apk_search = {
.help = "Search package by PATTERNs or by indexed dependencies", .help = "Search package by PATTERNs or by indexed dependencies",
.arguments = "PATTERN", .arguments = "PATTERN",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE, .open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.command_groups = APK_COMMAND_GROUP_QUERY,
.context_size = sizeof(struct search_ctx), .context_size = sizeof(struct search_ctx),
.optgroups = { &optgroup_global, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_applet },
.main = search_main, .main = search_main,
......
...@@ -50,6 +50,7 @@ static struct apk_applet apk_update = { ...@@ -50,6 +50,7 @@ static struct apk_applet apk_update = {
.help = "Update repository indexes from all remote repositories", .help = "Update repository indexes from all remote repositories",
.open_flags = APK_OPENF_WRITE, .open_flags = APK_OPENF_WRITE,
.forced_force = APK_FORCE_REFRESH, .forced_force = APK_FORCE_REFRESH,
.command_groups = APK_COMMAND_GROUP_SYSTEM,
.main = update_main, .main = update_main,
}; };
......
...@@ -182,6 +182,7 @@ static struct apk_applet apk_upgrade = { ...@@ -182,6 +182,7 @@ static struct apk_applet apk_upgrade = {
.name = "upgrade", .name = "upgrade",
.help = "Upgrade currently installed packages to match repositories", .help = "Upgrade currently installed packages to match repositories",
.open_flags = APK_OPENF_WRITE, .open_flags = APK_OPENF_WRITE,
.command_groups = APK_COMMAND_GROUP_SYSTEM,
.context_size = sizeof(struct upgrade_ctx), .context_size = sizeof(struct upgrade_ctx),
.optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet }, .optgroups = { &optgroup_global, &optgroup_commit, &optgroup_applet },
.main = upgrade_main, .main = upgrade_main,
......
...@@ -59,6 +59,7 @@ static struct apk_applet apk_verify = { ...@@ -59,6 +59,7 @@ static struct apk_applet apk_verify = {
.help = "Verify package integrity and signature", .help = "Verify package integrity and signature",
.arguments = "FILE...", .arguments = "FILE...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE, .open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.command_groups = APK_COMMAND_GROUP_REPO,
.forced_flags = APK_ALLOW_UNTRUSTED, .forced_flags = APK_ALLOW_UNTRUSTED,
.main = verify_main, .main = verify_main,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment