From 61213c401886884b73406c0e536b2f5ee97425e1 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 19 Jun 2009 15:40:37 +0200 Subject: 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. --- src/add.c | 2 +- src/apk.c | 42 +++++++++++++++++++++++++++--------------- src/del.c | 2 +- src/fetch.c | 3 ++- src/index.c | 2 +- src/info.c | 3 ++- src/search.c | 3 +-- src/ver.c | 2 +- 8 files changed, 36 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/add.c b/src/add.c index 43e6340..91f9380 100644 --- a/src/add.c +++ b/src/add.c @@ -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, diff --git a/src/apk.c b/src/apk.c index d52e3a2..64b0adb 100644 --- a/src/apk.c +++ b/src/apk.c @@ -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 = "/"; diff --git a/src/del.c b/src/del.c index 2a07eee..b5b0477 100644 --- a/src/del.c +++ b/src/del.c @@ -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, diff --git a/src/info.c b/src/info.c index b7071a5..3b24953 100644 --- a/src/info.c +++ b/src/info.c @@ -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, diff --git a/src/ver.c b/src/ver.c index f6d317a..1d513bc 100644 --- a/src/ver.c +++ b/src/ver.c @@ -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, -- cgit v1.2.3-60-g2f50