diff options
author | Timo Teräs <timo.teras@iki.fi> | 2020-04-24 11:49:14 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2020-05-06 13:05:19 +0300 |
commit | 5258b484bf13441d3d5c199e3c8d70cf2a75b3ca (patch) | |
tree | 6c979789a3b26eab2479224be5f6919e49841019 /src/apk.c | |
parent | d61c009f7a7ba9c99797855d8cd4e0a503c2fda5 (diff) | |
download | apk-tools-5258b484bf13441d3d5c199e3c8d70cf2a75b3ca.tar.gz apk-tools-5258b484bf13441d3d5c199e3c8d70cf2a75b3ca.tar.bz2 apk-tools-5258b484bf13441d3d5c199e3c8d70cf2a75b3ca.tar.xz apk-tools-5258b484bf13441d3d5c199e3c8d70cf2a75b3ca.zip |
add script to autogenerate help from man pages
This creates main help like:
--
usage: apk [<OPTIONS>...] COMMAND [<ARGUMENTS>...]
Package installation and removal:
add Add packages to WORLD and commit changes
del Remove packages from WORLD and commit changes
System maintenance:
fix Check WORLD against the system and ensure consistency
update Update repository indexes
upgrade Install upgrades available from repositories
cache Commands related to the management of an offline package cache
Querying package information:
info Give detailed information about packages or repositories
list List packages matching a pattern or other criteria
dot Generate graphviz graphs
policy Show repository policy for packages
Repository maintenance:
index Create repository index file from packages
fetch Download packages from global repositories to a local directory
manifest Show checksums of package contents
verify Verify package integrity and signature
Miscellaneous:
audit Audit directories for changes
stats Show statistics about repositories and installations
version Compare package versions or perform tests on version strings
This apk has coffee making abilities.
--
And applet specific help like:
--
usage: apk add [<OPTIONS>...] PACKAGES...
Description:
apk add adds the requested packages to WORLD and installs (or upgrades)
them if not already present, ensuring all dependencies are met.
Options:
--initdb Initialize a new package database
-l, --latest Disables normal heuristics for choosing which repository to install a
-u, --upgrade When adding packages which are already installed, upgrade them rather
-t, --virtual NAME
Instead of adding the specified packages to WORLD, create a new
--no-chown Do not change file owner or group
--
Diffstat (limited to 'src/apk.c')
-rw-r--r-- | src/apk.c | 75 |
1 files changed, 13 insertions, 62 deletions
@@ -192,8 +192,8 @@ static int option_parse_global(void *ctx, struct apk_db_options *dbopts, int opt static const struct apk_option options_global[] = { { 'h', "help" }, - { 'p', "root", required_argument, "DIR" }, - { 'X', "repository", required_argument, "REPO" }, + { 'p', "root", required_argument }, + { 'X', "repository", required_argument }, { 'q', "quiet" }, { 'v', "verbose" }, { 'i', "interactive" }, @@ -207,23 +207,23 @@ static const struct apk_option options_global[] = { { 0x123, "force-refresh" }, { 'U', "update-cache" }, { 0x101, "progress" }, - { 0x10f, "progress-fd", required_argument, "FD" }, + { 0x10f, "progress-fd", required_argument }, { 0x110, "no-progress" }, { 0x106, "purge" }, { 0x103, "allow-untrusted" }, - { 0x105, "wait", required_argument, "TIME" }, - { 0x107, "keys-dir", required_argument, "KEYSDIR" }, - { 0x108, "repositories-file", required_argument, "REPOFILE" }, + { 0x105, "wait", required_argument }, + { 0x107, "keys-dir", required_argument }, + { 0x108, "repositories-file", required_argument }, { 0x109, "no-network" }, { 0x115, "no-cache" }, - { 0x116, "cache-dir", required_argument, "CACHEDIR" }, - { 0x119, "cache-max-age", required_argument, "AGE" }, - { 0x112, "arch", required_argument, "ARCH" }, + { 0x116, "cache-dir", required_argument }, + { 0x119, "cache-max-age", required_argument }, + { 0x112, "arch", required_argument }, { 0x114, "print-arch" }, #ifdef TEST_MODE - { 0x200, "test-repo", required_argument, "REPO" }, - { 0x201, "test-instdb", required_argument, "INSTALLED" }, - { 0x202, "test-world", required_argument, "WORLD DEPS" }, + { 0x200, "test-repo", required_argument }, + { 0x201, "test-instdb", required_argument }, + { 0x202, "test-world", required_argument }, #endif }; @@ -280,59 +280,10 @@ const struct apk_option_group optgroup_commit = { .parse = option_parse_commit, }; -static int format_option(char *buf, size_t len, const struct apk_option *o, - const char *separator) -{ - int i = 0; - - if (o->val <= 0xff && isalnum(o->val)) { - i += snprintf(&buf[i], len - i, "-%c", o->val); - if (o->name != NULL) - i += snprintf(&buf[i], len - i, "%s", separator); - } - if (o->name != NULL) - i += snprintf(&buf[i], len - i, "--%s", o->name); - if (o->arg_name != NULL) - i += snprintf(&buf[i], len - i, " %s", o->arg_name); - - return i; -} - -static void print_usage(const char *cmd, const char *args, const struct apk_option_group **optgroups) -{ - struct apk_indent indent = { .indent = 11 }; - const struct apk_option *opts; - char word[128]; - int g, i, j; - - indent.x = printf("\nusage: apk %s", cmd) - 1; - for (g = 0; optgroups[g]; g++) { - opts = optgroups[g]->options; - for (i = 0; i < optgroups[g]->num_options; i++) { - if (!opts[i].name) continue; - j = 0; - word[j++] = '['; - j += format_option(&word[j], sizeof(word) - j, &opts[i], "|"); - word[j++] = ']'; - apk_print_indented(&indent, APK_BLOB_PTR_LEN(word, j)); - } - } - if (args != NULL) - apk_print_indented(&indent, APK_BLOB_STR(args)); - printf("\n"); -} - static int usage(struct apk_applet *applet) { version(); - if (applet == NULL) { - print_usage("<COMMAND>", "[<args>...]", default_optgroups); - } else { - print_usage(applet->name, applet->arguments, &applet->optgroups[1]); - } - - printf("\nThis apk has coffee making abilities.\n"); - + apk_help(applet); return 1; } |