MCPcopy Create free account
hub / github.com/git/git / cmd_main

Function cmd_main

t/helper/test-tool.c:108–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108int 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}

Callers

nothing calls this directly

Calls 5

parse_optionsFunction · 0.85
chdirFunction · 0.85
errorFunction · 0.85
die_usageFunction · 0.70
dieFunction · 0.50

Tested by

no test coverage detected