6 * opt - simple command line parsing
8 * Simple but powerful command line parsing.
14 * #include <ccan/opt/opt.h>
18 * static bool someflag;
20 * static char *somestring;
22 * static struct opt_table opts[] = {
23 * OPT_WITHOUT_ARG("--verbose|-v", opt_inc_intval, &verbose,
24 * "Verbose mode (can be specified more than once)"),
25 * OPT_WITHOUT_ARG("--someflag", opt_set_bool, &someflag,
27 * OPT_WITH_ARG("--somefile=<filename>", opt_set_charp, opt_show_charp,
28 * &somestring, "Set somefile to <filename>"),
29 * OPT_WITHOUT_ARG("--usage|--help|-h", opt_usage_and_exit,
30 * "args...\nA silly test program.",
31 * "Print this message."),
35 * int main(int argc, char *argv[])
39 * opt_register_table(opts, NULL);
40 * // For fun, register an extra one.
41 * opt_register_noarg("--no-someflag", opt_set_invbool, &someflag,
43 * if (!opt_parse(&argc, argv, opt_log_stderr))
46 * printf("someflag = %i, verbose = %i, somestring = %s\n",
47 * someflag, verbose, somestring);
48 * printf("%u args left over:", argc - 1);
49 * for (i = 1; i < argc; i++)
50 * printf(" %s", argv[i]);
55 * License: GPL (v2 or any later version)
56 * Author: Rusty Russell <rusty@rustcorp.com.au>
58 int main(int argc, char *argv[])
63 if (strcmp(argv[1], "depends") == 0) {
64 printf("ccan/cast\n");
65 printf("ccan/compiler\n");
66 printf("ccan/typesafe_cb\n");