int ret;
if (argc < 2) {
+ cmdline_usage(cmdline, NULL);
return EINVAL;
}
if (parse_options) {
ret = cmdline_parse_options(cmdline, argc, argv);
if (ret != 0) {
+ cmdline_usage(cmdline, NULL);
return ret;
}
} else {
}
ret = cmdline_match(cmdline);
- if (!cmdline_show_help && ret != 0) {
- return ret;
+
+ if (ret != 0 || cmdline_show_help) {
+ const char *name = NULL;
+
+ if (cmdline->match_cmd != NULL) {
+ name = cmdline->match_cmd->name;
+ }
+
+ cmdline_usage(cmdline, name);
+
+ if (cmdline_show_help) {
+ ret = EAGAIN;
+ }
}
- return 0;
+ return ret;
}
static void cmdline_usage_command(struct cmdline_context *cmdline,
TALLOC_CTX *tmp_ctx;
int ret;
- if (cmdline_show_help) {
- const char *name = NULL;
-
- if (cmd != NULL) {
- name = cmdline->match_cmd->name;
- }
-
- cmdline_usage(cmdline, name);
-
- if (result != NULL) {
- *result = 0;
- }
- return EAGAIN;
- }
-
if (cmd == NULL) {
return ENOENT;
}
ok <<EOF
Usage: test5 [<options>] <command> [<args>]
+Help Options:
+ -h, --help Show this help message
+
+Commands:
+ action one action one help
+ action two action two help
+Usage: test5 [<options>] <command> [<args>]
+
+Help Options:
+ -h, --help Show this help message
+
+Commands:
+ action one action one help
+ action two action two help
+Usage: test5 [<options>] <command> [<args>]
+
Help Options:
-h, --help Show this help message
const char *argv2[] = { "test5", "action" };
const char *argv3[] = { "test5", "action", "--help" };
const char *argv4[] = { "test5", "action", "one" };
- int ret, result;
+ int ret;
mem_ctx = talloc_new(NULL);
assert(mem_ctx != NULL);
assert(ret == 0);
ret = cmdline_parse(cmdline, 2, argv1, true);
- assert(ret == 0);
-
- ret = cmdline_run(cmdline, NULL, &result);
assert(ret == EAGAIN);
- assert(result == 0);
ret = cmdline_parse(cmdline, 2, argv2, true);
assert(ret == ENOENT);
ret = cmdline_parse(cmdline, 3, argv3, true);
- assert(ret == 0);
+ assert(ret == EAGAIN);
ret = cmdline_parse(cmdline, 3, argv4, true);
assert(ret == 0);