test/run_storage: print a combined usage text for all commands

This commit is contained in:
Max Kellermann 2024-05-15 11:10:08 +02:00
parent 57fad1d4b2
commit ca8a2aeb7b
1 changed files with 11 additions and 4 deletions

View File

@ -20,6 +20,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
static constexpr auto usage_text = R"(Usage: run_storage COMMAND URI ...
Available commands:
ls URI PATH
stat URI PATH
)";
class GlobalInit { class GlobalInit {
const ScopeNetInit net_init; const ScopeNetInit net_init;
EventThread io_thread; EventThread io_thread;
@ -110,7 +117,7 @@ int
main(int argc, char **argv) main(int argc, char **argv)
try { try {
if (argc < 3) { if (argc < 3) {
fprintf(stderr, "Usage: run_storage COMMAND URI ...\n"); fputs(usage_text, stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -121,7 +128,7 @@ try {
if (StringIsEqual(command, "ls")) { if (StringIsEqual(command, "ls")) {
if (argc != 4) { if (argc != 4) {
fprintf(stderr, "Usage: run_storage ls URI PATH\n"); fputs(usage_text, stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -133,7 +140,7 @@ try {
return Ls(*storage, path); return Ls(*storage, path);
} else if (StringIsEqual(command, "stat")) { } else if (StringIsEqual(command, "stat")) {
if (argc != 4) { if (argc != 4) {
fprintf(stderr, "Usage: run_storage stat URI PATH\n"); fputs(usage_text, stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -144,7 +151,7 @@ try {
return Stat(*storage, path); return Stat(*storage, path);
} else { } else {
fprintf(stderr, "Unknown command\n"); fprintf(stderr, "Unknown command\n\n%s", usage_text);
return EXIT_FAILURE; return EXIT_FAILURE;
} }