util/opts: print help as a command line
This commit is contained in:
@ -18,7 +18,7 @@ static void print_help(option_t *options, const char *cmd)
|
|||||||
option_t *option = &options[i];
|
option_t *option = &options[i];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
len += printf(" -%s", option->name);
|
len += printf(" --%s", option->name);
|
||||||
if (option->default_value) {
|
if (option->default_value) {
|
||||||
len += printf("[=%s]", option->default_value);
|
len += printf("[=%s]", option->default_value);
|
||||||
} else if (option->value_mapping) {
|
} else if (option->value_mapping) {
|
||||||
@ -43,7 +43,9 @@ static void print_help(option_t *options, const char *cmd)
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("Configuration:\n");
|
printf("Command line:\n\n");
|
||||||
|
|
||||||
|
printf("$ %s \\\n", cmd);
|
||||||
for (int i = 0; options[i].name; i++) {
|
for (int i = 0; options[i].name; i++) {
|
||||||
option_t *option = &options[i];
|
option_t *option = &options[i];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@ -56,36 +58,31 @@ static void print_help(option_t *options, const char *cmd)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
while ((token = strsep(&string, OPTION_VALUE_LIST_SEP)) != NULL) {
|
while ((token = strsep(&string, OPTION_VALUE_LIST_SEP)) != NULL) {
|
||||||
len = printf(" -%s=", option->name);
|
len = printf(" --%s=", option->name);
|
||||||
if (len < OPT_LENGTH) {
|
printf("%s \\\n", token);
|
||||||
printf("%*s", OPT_LENGTH-len, " ");
|
|
||||||
}
|
|
||||||
printf("%s\n", token);
|
|
||||||
}
|
}
|
||||||
} else if (option->value_string) {
|
} else if (option->value_string) {
|
||||||
len += printf(" -%s=", option->name);
|
len += printf(" --%s=", option->name);
|
||||||
if (len < OPT_LENGTH) {
|
|
||||||
printf("%*s", OPT_LENGTH-len, " ");
|
|
||||||
}
|
|
||||||
printf(option->format, option->value_string);
|
printf(option->format, option->value_string);
|
||||||
printf("\n");
|
printf(" \\\n");
|
||||||
} else {
|
} else {
|
||||||
len += printf(" -%s=", option->name);
|
bool found = false;
|
||||||
if (len < OPT_LENGTH) {
|
len += printf(" --%s=", option->name);
|
||||||
printf("%*s", OPT_LENGTH-len, " ");
|
|
||||||
}
|
|
||||||
if (option->value_mapping) {
|
if (option->value_mapping) {
|
||||||
for (int j = 0; option->value_mapping[j].name; j++) {
|
for (int j = 0; option->value_mapping[j].name; j++) {
|
||||||
if (option->value_mapping[j].value == *option->value_uint) {
|
if (option->value_mapping[j].value == *option->value_uint) {
|
||||||
printf("%s - ", option->value_mapping[j].name);
|
printf("%s", option->value_mapping[j].name);
|
||||||
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned mask = UINT_MAX >> ((sizeof(*option->value_uint) - option->size) * 8);
|
if (!found) {
|
||||||
printf(option->format, *option->value_uint & mask);
|
unsigned mask = UINT_MAX >> ((sizeof(*option->value_uint) - option->size) * 8);
|
||||||
printf("\n");
|
printf(option->format, *option->value_uint & mask);
|
||||||
|
}
|
||||||
|
printf(" \\\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
Reference in New Issue
Block a user