| 1 | #include "git-compat-util.h" |
| 2 | #include "test-tool.h" |
| 3 | #include "test-tool-utils.h" |
| 4 | #include "trace2.h" |
| 5 | #include "parse-options.h" |
| 6 | |
| 7 | static const char * const test_tool_usage[] = { |
| 8 | "test-tool [-C <directory>] <command [<arguments>...]]", |
| 9 | NULL |
| 10 | }; |
| 11 | |
| 12 | static struct test_cmd cmds[] = { |
| 13 | { "advise", cmd__advise_if_enabled }, |
| 14 | { "bitmap", cmd__bitmap }, |
| 15 | { "bloom", cmd__bloom }, |
| 16 | { "bundle-uri", cmd__bundle_uri }, |
| 17 | { "cache-tree", cmd__cache_tree }, |
| 18 | { "chmtime", cmd__chmtime }, |
| 19 | { "config", cmd__config }, |
| 20 | { "crontab", cmd__crontab }, |
| 21 | { "csprng", cmd__csprng }, |
| 22 | { "date", cmd__date }, |
| 23 | { "delete-gpgsig", cmd__delete_gpgsig }, |
| 24 | { "delta", cmd__delta }, |
| 25 | { "dir-iterator", cmd__dir_iterator }, |
| 26 | { "drop-caches", cmd__drop_caches }, |
| 27 | { "dump-cache-tree", cmd__dump_cache_tree }, |
| 28 | { "dump-fsmonitor", cmd__dump_fsmonitor }, |
| 29 | { "dump-reftable", cmd__dump_reftable }, |
| 30 | { "dump-split-index", cmd__dump_split_index }, |
| 31 | { "dump-untracked-cache", cmd__dump_untracked_cache }, |
| 32 | { "env-helper", cmd__env_helper }, |
| 33 | { "example-tap", cmd__example_tap }, |
| 34 | { "find-pack", cmd__find_pack }, |
| 35 | { "fsmonitor-client", cmd__fsmonitor_client }, |
| 36 | { "genrandom", cmd__genrandom }, |
| 37 | { "genzeros", cmd__genzeros }, |
| 38 | { "getcwd", cmd__getcwd }, |
| 39 | { "hashmap", cmd__hashmap }, |
| 40 | { "hash-speed", cmd__hash_speed }, |
| 41 | { "hexdump", cmd__hexdump }, |
| 42 | { "json-writer", cmd__json_writer }, |
| 43 | { "lazy-init-name-hash", cmd__lazy_init_name_hash }, |
| 44 | { "match-trees", cmd__match_trees }, |
| 45 | { "mergesort", cmd__mergesort }, |
| 46 | { "mktemp", cmd__mktemp }, |
| 47 | { "name-hash", cmd__name_hash }, |
| 48 | { "online-cpus", cmd__online_cpus }, |
| 49 | { "pack-deltas", cmd__pack_deltas }, |
| 50 | { "pack-mtimes", cmd__pack_mtimes }, |
| 51 | { "parse-options", cmd__parse_options }, |
| 52 | { "parse-options-flags", cmd__parse_options_flags }, |
| 53 | { "parse-pathspec-file", cmd__parse_pathspec_file }, |
| 54 | { "parse-subcommand", cmd__parse_subcommand }, |
| 55 | { "partial-clone", cmd__partial_clone }, |
| 56 | { "path-utils", cmd__path_utils }, |
| 57 | { "path-walk", cmd__path_walk }, |
| 58 | { "pcre2-config", cmd__pcre2_config }, |
| 59 | { "pkt-line", cmd__pkt_line }, |
| 60 | { "proc-receive", cmd__proc_receive }, |
| 61 | { "progress", cmd__progress }, |
| 62 | { "reach", cmd__reach }, |
| 63 | { "read-cache", cmd__read_cache }, |
| 64 | { "read-graph", cmd__read_graph }, |
| 65 | { "read-midx", cmd__read_midx }, |
| 66 | { "ref-store", cmd__ref_store }, |
| 67 | { "rot13-filter", cmd__rot13_filter }, |
| 68 | { "regex", cmd__regex }, |
| 69 | { "repository", cmd__repository }, |
| 70 | { "revision-walking", cmd__revision_walking }, |
| 71 | { "run-command", cmd__run_command }, |
| 72 | { "scrap-cache-tree", cmd__scrap_cache_tree }, |
| 73 | { "serve-v2", cmd__serve_v2 }, |
| 74 | { "sha1", cmd__sha1 }, |
| 75 | { "sha1-is-sha1dc", cmd__sha1_is_sha1dc }, |
| 76 | { "sha1-unsafe", cmd__sha1_unsafe }, |
| 77 | { "sha256", cmd__sha256 }, |
| 78 | { "sigchain", cmd__sigchain }, |
| 79 | { "simple-ipc", cmd__simple_ipc }, |
| 80 | { "string-list", cmd__string_list }, |
| 81 | { "submodule", cmd__submodule }, |
| 82 | { "submodule-config", cmd__submodule_config }, |
| 83 | { "submodule-nested-repo-config", cmd__submodule_nested_repo_config }, |
| 84 | { "subprocess", cmd__subprocess }, |
| 85 | { "synthesize", cmd__synthesize }, |
| 86 | { "trace2", cmd__trace2 }, |
| 87 | { "truncate", cmd__truncate }, |
| 88 | { "userdiff", cmd__userdiff }, |
| 89 | { "xml-encode", cmd__xml_encode }, |
| 90 | { "wildmatch", cmd__wildmatch }, |
| 91 | #ifdef GIT_WINDOWS_NATIVE |
| 92 | { "windows-named-pipe", cmd__windows_named_pipe }, |
| 93 | #endif |
| 94 | { "write-cache", cmd__write_cache }, |
| 95 | { "zlib", cmd__zlib }, |
| 96 | }; |
| 97 | |
| 98 | static NORETURN void die_usage(void) |
| 99 | { |
| 100 | size_t i; |
| 101 | |
| 102 | fprintf(stderr, "usage: test-tool <toolname> [args]\n"); |
| 103 | for (i = 0; i < ARRAY_SIZE(cmds); i++) |
| 104 | fprintf(stderr, " %s\n", cmds[i].name); |
| 105 | exit(128); |
| 106 | } |
| 107 | |
| 108 | int cmd_main(int argc, const char **argv) |
| 109 | { |
| 110 | const char *working_directory = NULL; |
| 111 | struct option options[] = { |
| 112 | OPT_STRING('C', NULL, &working_directory, "directory", |
| 113 | "change the working directory"), |
| 114 | OPT_END() |
| 115 | }; |
| 116 | |
| 117 | BUG_exit_code = 99; |
| 118 | argc = parse_options(argc, argv, NULL, options, test_tool_usage, |
| 119 | PARSE_OPT_STOP_AT_NON_OPTION | |
| 120 | PARSE_OPT_KEEP_ARGV0); |
| 121 | |
| 122 | if (argc < 2) |
| 123 | die_usage(); |
| 124 | |
| 125 | if (working_directory && chdir(working_directory) < 0) |
| 126 | die("Could not cd to '%s'", working_directory); |
| 127 | |
| 128 | for (size_t i = 0; i < ARRAY_SIZE(cmds); i++) { |
| 129 | if (!strcmp(cmds[i].name, argv[1])) { |
| 130 | argv++; |
| 131 | argc--; |
| 132 | trace2_cmd_name(cmds[i].name); |
| 133 | trace2_cmd_list_config(); |
| 134 | trace2_cmd_list_env_vars(); |
| 135 | return cmds[i].fn(argc, argv); |
| 136 | } |
| 137 | } |
| 138 | error("there is no tool named '%s'", argv[1]); |
| 139 | die_usage(); |
| 140 | } |