Commit 61213c40 authored by Natanael Copa's avatar Natanael Copa

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.
parent 20a1217e
...@@ -182,7 +182,7 @@ static struct option add_options[] = { ...@@ -182,7 +182,7 @@ static struct option add_options[] = {
static struct apk_applet apk_add = { static struct apk_applet apk_add = {
.name = "add", .name = "add",
.usage = "[--initdb] [--upgrade|-u] [--virtual metaname] apkname...", .usage = "[--initdb] [-u|--upgrade] [-t|--virtual NAME] PACKAGE...",
.context_size = sizeof(struct add_ctx), .context_size = sizeof(struct add_ctx),
.num_options = ARRAY_SIZE(add_options), .num_options = ARRAY_SIZE(add_options),
.options = add_options, .options = add_options,
......
...@@ -43,20 +43,29 @@ int version(void) ...@@ -43,20 +43,29 @@ int version(void)
printf("apk-tools " APK_VERSION "\n"); printf("apk-tools " APK_VERSION "\n");
return 0; return 0;
} }
int usage(void)
{
struct apk_applet **a, *applet;
version(); int generic_usage(void)
printf("\nUsage:\n"); {
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++) { for (a = &__start_apkapplets; a < &__stop_apkapplets; a++) {
applet = *a; printf("%s ",
printf(" apk %s %s\n", (*a)->name);
applet->name, applet->usage);
} }
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; return 1;
} }
...@@ -110,8 +119,9 @@ static struct apk_repository_url *apk_repository_new(const char *url) ...@@ -110,8 +119,9 @@ static struct apk_repository_url *apk_repository_new(const char *url)
return r; return r;
} }
#define NUM_GENERIC_OPTS 9 #define NUM_GENERIC_OPTS 10
static struct option generic_options[32] = { static struct option generic_options[32] = {
{ "help", no_argument, NULL, 'h'},
{ "root", required_argument, NULL, 'p' }, { "root", required_argument, NULL, 'p' },
{ "repository", required_argument, NULL, 'X' }, { "repository", required_argument, NULL, 'X' },
{ "quiet", no_argument, NULL, 'q' }, { "quiet", no_argument, NULL, 'q' },
...@@ -165,6 +175,9 @@ int main(int argc, char **argv) ...@@ -165,6 +175,9 @@ int main(int argc, char **argv)
switch (r) { switch (r) {
case 0: case 0:
break; break;
case 'h':
return usage(applet);
break;
case 'p': case 'p':
apk_root = optarg; apk_root = optarg;
break; break;
...@@ -194,17 +207,16 @@ int main(int argc, char **argv) ...@@ -194,17 +207,16 @@ int main(int argc, char **argv)
apk_flags |= APK_SIMULATE; apk_flags |= APK_SIMULATE;
break; break;
default: default:
if (applet == NULL || applet->parse == NULL) if (applet == NULL || applet->parse == NULL ||
return usage(); applet->parse(ctx, r, optindex - NUM_GENERIC_OPTS,
if (applet->parse(ctx, r, optindex - NUM_GENERIC_OPTS,
optarg) != 0) optarg) != 0)
return usage(); return usage(applet);
break; break;
} }
} }
if (applet == NULL) if (applet == NULL)
return usage(); return usage(NULL);
if (apk_root == NULL) if (apk_root == NULL)
apk_root = "/"; apk_root = "/";
......
...@@ -60,7 +60,7 @@ out: ...@@ -60,7 +60,7 @@ out:
static struct apk_applet apk_del = { static struct apk_applet apk_del = {
.name = "del", .name = "del",
.usage = "apkname...", .usage = "PACKAGE...",
.main = del_main, .main = del_main,
}; };
......
...@@ -193,7 +193,8 @@ static struct option fetch_options[] = { ...@@ -193,7 +193,8 @@ static struct option fetch_options[] = {
static struct apk_applet apk_fetch = { static struct apk_applet apk_fetch = {
.name = "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), .context_size = sizeof(struct fetch_ctx),
.num_options = ARRAY_SIZE(fetch_options), .num_options = ARRAY_SIZE(fetch_options),
.options = fetch_options, .options = fetch_options,
......
...@@ -119,7 +119,7 @@ static struct option index_options[] = { ...@@ -119,7 +119,7 @@ static struct option index_options[] = {
static struct apk_applet apk_index = { static struct apk_applet apk_index = {
.name = "index", .name = "index",
.usage = "[-d indexfile] apkname...", .usage = "[-d|--delete INDEXFILE] FILE...",
.context_size = sizeof(struct index_ctx), .context_size = sizeof(struct index_ctx),
.num_options = ARRAY_SIZE(index_options), .num_options = ARRAY_SIZE(index_options),
.options = index_options, .options = index_options,
......
...@@ -266,7 +266,8 @@ static struct option info_options[] = { ...@@ -266,7 +266,8 @@ static struct option info_options[] = {
static struct apk_applet apk_info = { static struct apk_applet apk_info = {
.name = "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), .context_size = sizeof(struct info_ctx),
.num_options = ARRAY_SIZE(info_options), .num_options = ARRAY_SIZE(info_options),
.options = info_options, .options = info_options,
......
...@@ -28,7 +28,6 @@ struct search_query_ctx { ...@@ -28,7 +28,6 @@ struct search_query_ctx {
static int search_list_print(apk_hash_item item, void *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; struct apk_package *pkg = (struct apk_package *) item;
printf("%s", pkg->name->name); printf("%s", pkg->name->name);
...@@ -137,7 +136,7 @@ static struct option search_options[] = { ...@@ -137,7 +136,7 @@ static struct option search_options[] = {
static struct apk_applet apk_search = { static struct apk_applet apk_search = {
.name = "search", .name = "search",
.usage = "[--description|-d] [search_pattern]", .usage = "[--description|-d] PATTERN",
.context_size = sizeof(struct search_ctx), .context_size = sizeof(struct search_ctx),
.num_options = ARRAY_SIZE(search_options), .num_options = ARRAY_SIZE(search_options),
.options = search_options, .options = search_options,
......
...@@ -114,7 +114,7 @@ static struct option ver_options[] = { ...@@ -114,7 +114,7 @@ static struct option ver_options[] = {
static struct apk_applet apk_ver = { static struct apk_applet apk_ver = {
.name = "version", .name = "version",
.usage = "[-t version1 version2]", .usage = "[-t|--test version1 version2] [-c|--check]",
.context_size = sizeof(struct ver_ctx), .context_size = sizeof(struct ver_ctx),
.num_options = ARRAY_SIZE(ver_options), .num_options = ARRAY_SIZE(ver_options),
.options = ver_options, .options = ver_options,
......
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