2 #include <ccan/tap/tap.h>
8 #include <ccan/opt/opt.c>
9 #include <ccan/opt/usage.c>
10 #include <ccan/opt/helpers.c>
12 static char *my_cb(void *p)
18 int main(int argc, char *argv[])
23 opt_register_table(subtables, NULL);
24 opt_register_noarg("--kkk|-k", my_cb, NULL, "magic kkk option");
25 opt_register_noarg("-?", opt_usage_and_exit, "<MyArgs>...",
27 output = opt_usage("my name", "ExTrA Args");
29 ok1(strstr(output, "Usage: my name"));
30 ok1(strstr(output, "--jjj|-j|--lll|-l <arg>"));
31 ok1(strstr(output, "ExTrA Args"));
32 ok1(strstr(output, "-a "));
33 ok1(strstr(output, " Description of a\n"));
34 ok1(strstr(output, "-b <arg>"));
35 ok1(strstr(output, " Description of b (default: b)\n"));
36 ok1(strstr(output, "--ddd "));
37 ok1(strstr(output, " Description of ddd\n"));
38 ok1(strstr(output, "--eee <filename> "));
39 ok1(strstr(output, " (default: eee)\n"));
40 ok1(strstr(output, "long table options:\n"));
41 ok1(strstr(output, "--ggg|-g "));
42 ok1(strstr(output, " Description of ggg\n"));
43 ok1(strstr(output, "-h|--hhh <arg>"));
44 ok1(strstr(output, " Description of hhh\n"));
45 ok1(strstr(output, "--kkk|-k"));
46 ok1(strstr(output, "magic kkk option"));
47 /* This entry is hidden. */
48 ok1(!strstr(output, "--mmm|-m"));
51 /* NULL should use string from registered options. */
52 output = opt_usage("my name", NULL);
54 ok1(strstr(output, "Usage: my name"));
55 ok1(strstr(output, "--jjj|-j|--lll|-l <arg>"));
56 ok1(strstr(output, "<MyArgs>..."));
57 ok1(strstr(output, "-a "));
58 ok1(strstr(output, " Description of a\n"));
59 ok1(strstr(output, "-b <arg>"));
60 ok1(strstr(output, " Description of b (default: b)\n"));
61 ok1(strstr(output, "--ddd "));
62 ok1(strstr(output, " Description of ddd\n"));
63 ok1(strstr(output, "--eee <filename> "));
64 ok1(strstr(output, " (default: eee)\n"));
65 ok1(strstr(output, "long table options:\n"));
66 ok1(strstr(output, "--ggg|-g "));
67 ok1(strstr(output, " Description of ggg\n"));
68 ok1(strstr(output, "-h|--hhh <arg>"));
69 ok1(strstr(output, " Description of hhh\n"));
70 ok1(strstr(output, "--kkk|-k"));
71 ok1(strstr(output, "magic kkk option"));
72 /* This entry is hidden. */
73 ok1(!strstr(output, "--mmm|-m"));