forked from clibs/commander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
34 lines (29 loc) · 789 Bytes
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include "src/commander.h"
static void
verbose(command_t *self) {
printf("verbose: enabled\n");
}
static void
required(command_t *self) {
printf("required: %s\n", self->arg);
}
static void
optional(command_t *self) {
printf("optional: %s\n", self->arg);
}
int
main(int argc, char **argv){
command_t cmd;
command_init(&cmd, argv[0], "0.0.1");
command_option(&cmd, "-v", "--verbose", "enable verbose stuff", verbose);
command_option(&cmd, "-r", "--required <arg>", "required arg", required);
command_option(&cmd, "-o", "--optional [arg]", "optional arg", optional);
command_parse(&cmd, argc, argv);
printf("additional args:\n");
for (int i = 0; i < cmd.argc; ++i) {
printf(" - '%s'\n", cmd.argv[i]);
}
command_free(&cmd);
return 0;
}