Merge branch 'nd/help-align-command-desc'
[git] / t / helper / test-tool.c
1 #include "git-compat-util.h"
2 #include "test-tool.h"
3
4 struct test_cmd {
5         const char *name;
6         int (*fn)(int argc, const char **argv);
7 };
8
9 static struct test_cmd cmds[] = {
10         { "chmtime", cmd__chmtime },
11         { "config", cmd__config },
12         { "ctype", cmd__ctype },
13         { "date", cmd__date },
14         { "delta", cmd__delta },
15         { "drop-caches", cmd__drop_caches },
16         { "dump-cache-tree", cmd__dump_cache_tree },
17         { "dump-fsmonitor", cmd__dump_fsmonitor },
18         { "dump-split-index", cmd__dump_split_index },
19         { "dump-untracked-cache", cmd__dump_untracked_cache },
20         { "example-decorate", cmd__example_decorate },
21         { "genrandom", cmd__genrandom },
22         { "hashmap", cmd__hashmap },
23         { "hash-speed", cmd__hash_speed },
24         { "index-version", cmd__index_version },
25         { "json-writer", cmd__json_writer },
26         { "lazy-init-name-hash", cmd__lazy_init_name_hash },
27         { "match-trees", cmd__match_trees },
28         { "mergesort", cmd__mergesort },
29         { "mktemp", cmd__mktemp },
30         { "online-cpus", cmd__online_cpus },
31         { "parse-options", cmd__parse_options },
32         { "path-utils", cmd__path_utils },
33         { "pkt-line", cmd__pkt_line },
34         { "prio-queue", cmd__prio_queue },
35         { "reach", cmd__reach },
36         { "read-cache", cmd__read_cache },
37         { "read-midx", cmd__read_midx },
38         { "ref-store", cmd__ref_store },
39         { "regex", cmd__regex },
40         { "repository", cmd__repository },
41         { "revision-walking", cmd__revision_walking },
42         { "run-command", cmd__run_command },
43         { "scrap-cache-tree", cmd__scrap_cache_tree },
44         { "sha1", cmd__sha1 },
45         { "sha1-array", cmd__sha1_array },
46         { "sha256", cmd__sha256 },
47         { "sigchain", cmd__sigchain },
48         { "strcmp-offset", cmd__strcmp_offset },
49         { "string-list", cmd__string_list },
50         { "submodule-config", cmd__submodule_config },
51         { "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
52         { "subprocess", cmd__subprocess },
53         { "urlmatch-normalization", cmd__urlmatch_normalization },
54         { "xml-encode", cmd__xml_encode },
55         { "wildmatch", cmd__wildmatch },
56 #ifdef GIT_WINDOWS_NATIVE
57         { "windows-named-pipe", cmd__windows_named_pipe },
58 #endif
59         { "write-cache", cmd__write_cache },
60 };
61
62 static NORETURN void die_usage(void)
63 {
64         size_t i;
65
66         fprintf(stderr, "usage: test-tool <toolname> [args]\n");
67         for (i = 0; i < ARRAY_SIZE(cmds); i++)
68                 fprintf(stderr, "  %s\n", cmds[i].name);
69         exit(128);
70 }
71
72 int cmd_main(int argc, const char **argv)
73 {
74         int i;
75
76         BUG_exit_code = 99;
77         if (argc < 2)
78                 die_usage();
79
80         for (i = 0; i < ARRAY_SIZE(cmds); i++) {
81                 if (!strcmp(cmds[i].name, argv[1])) {
82                         argv++;
83                         argc--;
84                         return cmds[i].fn(argc, argv);
85                 }
86         }
87         error("there is no tool named '%s'", argv[1]);
88         die_usage();
89 }