6 * opt - simple command line parsing
8 * Simple but powerful command line parsing, built on top of getopt_long.
11 * #include <ccan/opt/opt.h>
15 * static bool someflag;
17 * static char *somestring;
19 * static struct opt_table opts[] = {
20 * { OPT_WITHOUT_ARG("--verbose/-v", opt_inc_intval, &verbose,
21 * "Verbose mode (can be specified more than once)") },
22 * { OPT_WITHOUT_ARG("--someflag", opt_set_bool, &someflag,
24 * { OPT_WITH_ARG("--somefile=<filename>", opt_set_charp, opt_show_charp,
25 * &somestring, "Set somefile to <filename>") },
26 * { OPT_WITHOUT_ARG("--usage/--help/-h", opt_usage_and_exit,
27 * "args...\nA silly test program.",
28 * "Print this message.") },
32 * int main(int argc, char *argv[])
36 * opt_register_table(opts, NULL);
37 * // For fun, register an extra one.
38 * opt_register_noarg("--no-someflag", opt_set_invbool, &someflag,
40 * if (!opt_parse(&argc, argv, opt_log_stderr))
43 * printf("someflag = %i, verbose = %i, somestring = %s\n",
44 * someflag, verbose, somestring);
45 * printf("%u args left over:", argc - 1);
46 * for (i = 1; i < argc; i++)
47 * printf(" %s", argv[i]);
52 * Licence: GPL (3 or any later version)
53 * Author: Rusty Russell <rusty@rustcorp.com.au>
55 int main(int argc, char *argv[])
60 if (strcmp(argv[1], "depends") == 0) {