struct cmdline_context {
const char *prog;
struct poptOption *options;
+ const char *section;
struct cmdline_command *commands;
int max_len;
poptContext pc;
int cmdline_init(TALLOC_CTX *mem_ctx,
const char *prog,
struct poptOption *options,
+ const char *section,
struct cmdline_command *commands,
struct cmdline_context **result)
{
talloc_free(cmdline);
return ret;
}
+ cmdline->section = section;
cmdline->commands = commands;
cmdline->max_len = max_len;
poptSetOtherOptionHelp(cmdline->pc, "[<options>] <command> [<args>]");
poptPrintHelp(cmdline->pc, stdout, 0);
- printf("\nCommands:\n");
+ printf("\n");
+ if (cmdline->section != NULL) {
+ printf("%s ", cmdline->section);
+ }
+ printf("Commands:\n");
for (i=0; cmdline->commands[i].name != NULL; i++) {
cmdline_usage_command(cmdline, &cmdline->commands[i], true);
* @param[in] mem_ctx Talloc memory context
* @param[in] prog Program name
* @param[in] options Command-line options
+ * @param[in] section Name of section grouping specified commands
* @param[in] commands Commands array
* @param[out] result New cmdline context
* @return 0 on success, errno on failure
int cmdline_init(TALLOC_CTX *mem_ctx,
const char *prog,
struct poptOption *options,
+ const char *section,
struct cmdline_command *commands,
struct cmdline_context **result);
mem_ctx = talloc_new(NULL);
assert(mem_ctx != NULL);
- ret = cmdline_init(mem_ctx, NULL, NULL, NULL, &cmdline);
+ ret = cmdline_init(mem_ctx, NULL, NULL, NULL, NULL, &cmdline);
assert(ret == EINVAL);
- ret = cmdline_init(mem_ctx, "test1", NULL, NULL, &cmdline);
+ ret = cmdline_init(mem_ctx, "test1", NULL, NULL, NULL, &cmdline);
assert(ret == EINVAL);
- ret = cmdline_init(mem_ctx, "test1", dummy_options, NULL, &cmdline);
+ ret = cmdline_init(mem_ctx,
+ "test1",
+ dummy_options,
+ NULL,
+ NULL,
+ &cmdline);
assert(ret == EINVAL);
talloc_free(mem_ctx);
mem_ctx = talloc_new(NULL);
assert(mem_ctx != NULL);
- ret = cmdline_init(mem_ctx, "test2", NULL, test2_nofunc, &cmdline);
+ ret = cmdline_init(mem_ctx,
+ "test2",
+ NULL,
+ NULL,
+ test2_nofunc,
+ &cmdline);
assert(ret == EINVAL);
- ret = cmdline_init(mem_ctx, "test2", NULL, test2_nohelp, &cmdline);
+ ret = cmdline_init(mem_ctx,
+ "test2",
+ NULL,
+ NULL,
+ test2_nohelp,
+ &cmdline);
assert(ret == EINVAL);
- ret = cmdline_init(mem_ctx, "test2", NULL, test2_long, &cmdline);
+ ret = cmdline_init(mem_ctx,
+ "test2",
+ NULL,
+ NULL,
+ test2_long,
+ &cmdline);
assert(ret == EINVAL);
- ret = cmdline_init(mem_ctx, "test2", NULL, test2_longhelp, &cmdline);
+ ret = cmdline_init(mem_ctx,
+ "test2",
+ NULL,
+ NULL,
+ test2_longhelp,
+ &cmdline);
assert(ret == EINVAL);
- ret = cmdline_init(mem_ctx, "test2", NULL, test2_twowords, &cmdline);
+ ret = cmdline_init(mem_ctx,
+ "test2",
+ NULL,
+ NULL,
+ test2_twowords,
+ &cmdline);
assert(ret == 0);
talloc_free(mem_ctx);
ret = cmdline_init(mem_ctx,
"test3",
test3_noname,
+ NULL,
dummy_commands,
&cmdline);
assert(ret == EINVAL);
ret = cmdline_init(mem_ctx,
"test3",
test3_notype,
+ NULL,
dummy_commands,
&cmdline);
assert(ret == EINVAL);
ret = cmdline_init(mem_ctx,
"test3",
test3_noarg,
+ NULL,
dummy_commands,
&cmdline);
assert(ret == EINVAL);
ret = cmdline_init(mem_ctx,
"test4",
test4_options,
+ NULL,
test4_commands,
&cmdline);
assert(ret == 0);
mem_ctx = talloc_new(NULL);
assert(mem_ctx != NULL);
- ret = cmdline_init(mem_ctx, "test5", NULL, action_commands, &cmdline);
+ ret = cmdline_init(mem_ctx,
+ "test5",
+ NULL,
+ NULL,
+ action_commands,
+ &cmdline);
assert(ret == 0);
ret = cmdline_parse(cmdline, 2, argv1, true);
mem_ctx = talloc_new(NULL);
assert(mem_ctx != NULL);
- ret = cmdline_init(mem_ctx, "test6", NULL, action_commands, &cmdline);
+ ret = cmdline_init(mem_ctx,
+ "test6",
+ NULL,
+ NULL,
+ action_commands,
+ &cmdline);
assert(ret == 0);
ret = cmdline_parse(cmdline, 2, argv1, false);