- /* I'd love to use long options, but that's not standard. */
- /* FIXME: popt ccan package? */
- while ((c = getopt(argc, argv, "sd:vnlx:t:k:")) != -1) {
- switch (c) {
- case 'd':
- if (optarg[0] != '/')
- dir = talloc_asprintf_append(NULL, "%s/%s",
- dir, optarg);
- else
- dir = optarg;
- prefix = talloc_append_string(talloc_basename(NULL,
- optarg),
- ": ");
- break;
- case 'l':
- list_tests();
- case 's':
- summary = true;
- break;
- case 'v':
- verbose++;
- break;
- case 'n':
- safe_mode = true;
- break;
- case 'k':
- keep_test(optarg);
- break;
- case 'x':
- btree_insert(cmdline_exclude, optarg);
- break;
- case 't':
- timeout = atoi(optarg);
- if (!timeout)
- errx(1, "Invalid timeout %s: 1 ms minumum",
- optarg);
- break;
- default:
- usage(argv[0]);
- }
- }
-
- if (optind < argc)
- usage(argv[0]);
-
- if (verbose >= 2)
- compile_verbose = true;
+ opt_register_arg("--dir|-d", opt_set_charp, opt_show_charp, &dir,
+ "use this directory");
+ opt_register_noarg("-n|--safe-mode", opt_set_bool, &safe_mode,
+ "do not compile anything");
+ opt_register_noarg("-l|--list-tests", list_tests, NULL,
+ "list tests ccanlint performs (and exit)");
+ opt_register_noarg("--test-dep-graph", test_dependency_graph, NULL,
+ "print dependency graph of tests in Graphviz .dot format");
+ opt_register_arg("-k|--keep <testname>", keep_test, NULL, NULL,
+ "keep results of <testname> (can be used multiple times)");
+ opt_register_noarg("--summary|-s", opt_set_bool, &summary,
+ "simply give one line summary");
+ opt_register_noarg("--verbose|-v", opt_inc_intval, &verbose,
+ "verbose mode (up to -vvvv)");
+ opt_register_arg("-x|--exclude <testname>", skip_test, NULL, NULL,
+ "exclude <testname> (can be used multiple times)");
+ opt_register_arg("-t|--timeout <milleseconds>", opt_set_uintval,
+ NULL, &timeout,
+ "ignore (terminate) tests that are slower than this");
+ opt_register_arg("--target <testname>", opt_set_charp,
+ NULL, &target,
+ "only run one test (and its prerequisites)");
+ opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
+ "\nA program for checking and guiding development"
+ " of CCAN modules.",
+ "This usage message");
+
+ opt_parse(&argc, argv, opt_log_stderr_exit);
+
+ if (dir[0] != '/')
+ dir = talloc_asprintf_append(NULL, "%s/%s", base_dir, dir);
+ while (strends(dir, "/"))
+ dir[strlen(dir)-1] = '\0';
+ if (dir != base_dir)
+ prefix = talloc_append_string(talloc_basename(NULL, dir), ": ");