Skip to content

Commit 4e26569

Browse files
peffgitster
authored andcommitted
test-tool: show tool list on error
Before we switched to one big test-tool binary, if you forgot the name of a tool, you could use tab-completion in the shell to get a hint. But these days, all you get is: $ t/helper/test-tool approxidate fatal: There is no test named 'approxidate' and you're stuck reading the source code to find it. Let's print a list of the available tools in this case. Signed-off-by: Jeff King <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a4b8ab5 commit 4e26569

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

t/helper/test-tool.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,23 @@ static struct test_cmd cmds[] = {
5555
{ "write-cache", cmd__write_cache },
5656
};
5757

58+
static NORETURN void die_usage(void)
59+
{
60+
size_t i;
61+
62+
fprintf(stderr, "usage: test-tool <toolname> [args]\n");
63+
for (i = 0; i < ARRAY_SIZE(cmds); i++)
64+
fprintf(stderr, " %s\n", cmds[i].name);
65+
exit(128);
66+
}
67+
5868
int cmd_main(int argc, const char **argv)
5969
{
6070
int i;
6171

6272
BUG_exit_code = 99;
6373
if (argc < 2)
64-
die("I need a test name!");
74+
die_usage();
6575

6676
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
6777
if (!strcmp(cmds[i].name, argv[1])) {
@@ -70,5 +80,6 @@ int cmd_main(int argc, const char **argv)
7080
return cmds[i].fn(argc, argv);
7181
}
7282
}
73-
die("There is no test named '%s'", argv[1]);
83+
error("there is no tool named '%s'", argv[1]);
84+
die_usage();
7485
}

0 commit comments

Comments
 (0)