diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2009-06-19 15:40:37 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2009-06-19 15:40:37 +0200 |
commit | 61213c401886884b73406c0e536b2f5ee97425e1 (patch) | |
tree | 1f9eccef792182e03adf39cfe4d6ed09471b4036 /src | |
parent | 20a1217e866f9fe15c4de3ed28144084509e4ffa (diff) | |
download | apk-tools-61213c401886884b73406c0e536b2f5ee97425e1.tar.gz apk-tools-61213c401886884b73406c0e536b2f5ee97425e1.tar.bz2 apk-tools-61213c401886884b73406c0e536b2f5ee97425e1.tar.xz apk-tools-61213c401886884b73406c0e536b2f5ee97425e1.zip |
improve --help output
apk --help will list the generic options only and give a list of commands
To get the details for a spefic command, 'apk command --help' should be used.
Diffstat (limited to 'src')
-rw-r--r-- | src/add.c | 2 | ||||
-rw-r--r-- | src/apk.c | 42 | ||||
-rw-r--r-- | src/del.c | 2 | ||||
-rw-r--r-- | src/fetch.c | 3 | ||||
-rw-r--r-- | src/index.c | 2 | ||||
-rw-r--r-- | src/info.c | 3 | ||||
-rw-r--r-- | src/search.c | 3 | ||||
-rw-r--r-- | src/ver.c | 2 |
8 files changed, 36 insertions, 23 deletions
@@ -182,7 +182,7 @@ static struct option add_options[] = { static struct apk_applet apk_add = { .name = "add", - .usage = "[--initdb] [--upgrade|-u] [--virtual metaname] apkname...", + .usage = "[--initdb] [-u|--upgrade] [-t|--virtual NAME] PACKAGE...", .context_size = sizeof(struct add_ctx), .num_options = ARRAY_SIZE(add_options), .options = add_options, @@ -43,20 +43,29 @@ int version(void) printf("apk-tools " APK_VERSION "\n"); return 0; } -int usage(void) -{ - struct apk_applet **a, *applet; - version(); - printf("\nUsage:\n"); +int generic_usage(void) +{ + struct apk_applet **a; + printf("usage: apk COMMAND [-h|--help] [-p|--root DIR] [-X|--repository REPO]\n" + "\t\t [-q|--quiet] [-v|--verbose] [-V|--version] [-f|--force]\n" + "\t\t [--progress] [--clean-protected] [--simulate] [ARGS]...\n\n" + "commands: "); for (a = &__start_apkapplets; a < &__stop_apkapplets; a++) { - applet = *a; - printf(" apk %s %s\n", - applet->name, applet->usage); + printf("%s ", + (*a)->name); } - printf("\nThis apk has coffee making abilities.\n\n"); + printf("\n\n"); + return 1; +} +int usage(struct apk_applet *applet) +{ + version(); + if (applet == NULL) + return generic_usage(); + printf("usage: apk %s %s\n\n", applet->name, applet->usage); return 1; } @@ -110,8 +119,9 @@ static struct apk_repository_url *apk_repository_new(const char *url) return r; } -#define NUM_GENERIC_OPTS 9 +#define NUM_GENERIC_OPTS 10 static struct option generic_options[32] = { + { "help", no_argument, NULL, 'h'}, { "root", required_argument, NULL, 'p' }, { "repository", required_argument, NULL, 'X' }, { "quiet", no_argument, NULL, 'q' }, @@ -165,6 +175,9 @@ int main(int argc, char **argv) switch (r) { case 0: break; + case 'h': + return usage(applet); + break; case 'p': apk_root = optarg; break; @@ -194,17 +207,16 @@ int main(int argc, char **argv) apk_flags |= APK_SIMULATE; break; default: - if (applet == NULL || applet->parse == NULL) - return usage(); - if (applet->parse(ctx, r, optindex - NUM_GENERIC_OPTS, + if (applet == NULL || applet->parse == NULL || + applet->parse(ctx, r, optindex - NUM_GENERIC_OPTS, optarg) != 0) - return usage(); + return usage(applet); break; } } if (applet == NULL) - return usage(); + return usage(NULL); if (apk_root == NULL) apk_root = "/"; @@ -60,7 +60,7 @@ out: static struct apk_applet apk_del = { .name = "del", - .usage = "apkname...", + .usage = "PACKAGE...", .main = del_main, }; diff --git a/src/fetch.c b/src/fetch.c index 826dc73..049c3ef 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -193,7 +193,8 @@ static struct option fetch_options[] = { static struct apk_applet apk_fetch = { .name = "fetch", - .usage = "[-R|--recursive|--stdout] [--link|-L] [-o dir] apkname...", + .usage = "[-R|--recursive|--stdout] [-L|--link] [-o|--output DIR]\n" + "\t\t PACKAGE...", .context_size = sizeof(struct fetch_ctx), .num_options = ARRAY_SIZE(fetch_options), .options = fetch_options, diff --git a/src/index.c b/src/index.c index 7bf11ae..824d60e 100644 --- a/src/index.c +++ b/src/index.c @@ -119,7 +119,7 @@ static struct option index_options[] = { static struct apk_applet apk_index = { .name = "index", - .usage = "[-d indexfile] apkname...", + .usage = "[-d|--delete INDEXFILE] FILE...", .context_size = sizeof(struct index_ctx), .num_options = ARRAY_SIZE(index_options), .options = index_options, @@ -266,7 +266,8 @@ static struct option info_options[] = { static struct apk_applet apk_info = { .name = "info", - .usage = "", + .usage = "[-L|--contents] [-e|--installed] [-W|--who-owns] [-R|--depends]\n" + "\t\t[-r|--rdepends] PACKAGE...", .context_size = sizeof(struct info_ctx), .num_options = ARRAY_SIZE(info_options), .options = info_options, diff --git a/src/search.c b/src/search.c index 5cfca5a..ada8606 100644 --- a/src/search.c +++ b/src/search.c @@ -28,7 +28,6 @@ struct search_query_ctx { static int search_list_print(apk_hash_item item, void *ctx) { - //struct apk_database *db = (struct apk_database *) ctx; struct apk_package *pkg = (struct apk_package *) item; printf("%s", pkg->name->name); @@ -137,7 +136,7 @@ static struct option search_options[] = { static struct apk_applet apk_search = { .name = "search", - .usage = "[--description|-d] [search_pattern]", + .usage = "[--description|-d] PATTERN", .context_size = sizeof(struct search_ctx), .num_options = ARRAY_SIZE(search_options), .options = search_options, @@ -114,7 +114,7 @@ static struct option ver_options[] = { static struct apk_applet apk_ver = { .name = "version", - .usage = "[-t version1 version2]", + .usage = "[-t|--test version1 version2] [-c|--check]", .context_size = sizeof(struct ver_ctx), .num_options = ARRAY_SIZE(ver_options), .options = ver_options, |