2 #include <ccan/tap/tap.h>
8 #include <ccan/opt/opt.c>
9 #include <ccan/opt/usage.c>
10 #include <ccan/opt/helpers.c>
11 #include <ccan/opt/parse.c>
13 static char *my_cb(void *p)
18 static void reset_options(void)
22 opt_count = opt_num_short = opt_num_short_arg = opt_num_long = 0;
26 int main(int argc, char *argv[])
31 opt_register_table(subtables, NULL);
32 opt_register_noarg("--kkk|-k", my_cb, NULL, "magic kkk option");
33 opt_register_noarg("-?", opt_usage_and_exit, "<MyArgs>...",
35 output = opt_usage("my name", "ExTrA Args");
37 ok1(strstr(output, "Usage: my name"));
38 ok1(strstr(output, "--jjj|-j|--lll|-l <arg>"));
39 ok1(strstr(output, "ExTrA Args"));
40 ok1(strstr(output, "-a "));
41 ok1(strstr(output, " Description of a\n"));
42 ok1(strstr(output, "-b <arg>"));
43 ok1(strstr(output, " Description of b (default: b)\n"));
44 ok1(strstr(output, "--ddd "));
45 ok1(strstr(output, " Description of ddd\n"));
46 ok1(strstr(output, "--eee <filename> "));
47 ok1(strstr(output, " (default: eee)\n"));
48 ok1(strstr(output, "long table options:\n"));
49 ok1(strstr(output, "--ggg|-g "));
50 ok1(strstr(output, " Description of ggg\n"));
51 ok1(strstr(output, "-h|--hhh <arg>"));
52 ok1(strstr(output, " Description of hhh\n"));
53 ok1(strstr(output, "--kkk|-k"));
54 ok1(strstr(output, "magic kkk option"));
55 /* This entry is hidden. */
56 ok1(!strstr(output, "--mmm|-m"));
59 /* NULL should use string from registered options. */
60 output = opt_usage("my name", NULL);
62 ok1(strstr(output, "Usage: my name"));
63 ok1(strstr(output, "--jjj|-j|--lll|-l <arg>"));
64 ok1(strstr(output, "<MyArgs>..."));
65 ok1(strstr(output, "-a "));
66 ok1(strstr(output, " Description of a\n"));
67 ok1(strstr(output, "-b <arg>"));
68 ok1(strstr(output, " Description of b (default: b)\n"));
69 ok1(strstr(output, "--ddd "));
70 ok1(strstr(output, " Description of ddd\n"));
71 ok1(strstr(output, "--eee <filename> "));
72 ok1(strstr(output, " (default: eee)\n"));
73 ok1(strstr(output, "long table options:\n"));
74 ok1(strstr(output, "--ggg|-g "));
75 ok1(strstr(output, " Description of ggg\n"));
76 ok1(strstr(output, "-h|--hhh <arg>"));
77 ok1(strstr(output, " Description of hhh\n"));
78 ok1(strstr(output, "--kkk|-k"));
79 ok1(strstr(output, "magic kkk option"));
80 /* This entry is hidden. */
81 ok1(!strstr(output, "--mmm|-m"));
85 /* Empty table test. */
86 output = opt_usage("nothing", NULL);
87 ok1(strstr(output, "Usage: nothing \n"));
91 opt_register_noarg("--aaa", test_noarg, NULL, "AAAAll");
92 output = opt_usage("onearg", NULL);
93 ok1(strstr(output, "Usage: onearg \n"));
94 ok1(strstr(output, "--aaa"));
95 ok1(strstr(output, "AAAAll"));