diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-03 20:06:33 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-03 20:45:48 +0200 |
commit | 62cc3a9c5af2fd7cc8847a577b6b911c79e110e7 (patch) | |
tree | b11d05c7cd25c86aeb7cf8b3315e6f09f407a0f8 /src/tools/wg.c | |
parent | tai64n: don't forget to add 2^62, to be in spec (diff) | |
download | wireguard-monolithic-historical-62cc3a9c5af2fd7cc8847a577b6b911c79e110e7.tar.xz wireguard-monolithic-historical-62cc3a9c5af2fd7cc8847a577b6b911c79e110e7.zip |
tools: improve error reporting and detection
Diffstat (limited to '')
-rw-r--r-- | src/tools/wg.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/tools/wg.c b/src/tools/wg.c index d4d2965..ee19387 100644 --- a/src/tools/wg.c +++ b/src/tools/wg.c @@ -23,12 +23,13 @@ static const struct { { "pubkey", pubkey_main, "Reads a private key from stdin and writes a public key to stdout" } }; -static void show_usage(void) +static void show_usage(FILE *file) { - fprintf(stderr, "Usage: %s <cmd> [<args>]\n\n", PROG_NAME); - fprintf(stderr, "Available subcommands:\n"); + fprintf(file, "Usage: %s <cmd> [<args>]\n\n", PROG_NAME); + fprintf(file, "Available subcommands:\n"); for (size_t i = 0; i < sizeof(subcommands) / sizeof(subcommands[0]); ++i) - fprintf(stderr, " %s: %s\n", subcommands[i].subcommand, subcommands[i].description); + fprintf(file, " %s: %s\n", subcommands[i].subcommand, subcommands[i].description); + fprintf(file, "You may pass `--help' to any of these subcommands to view usage.\n"); } int main(int argc, char *argv[]) @@ -37,8 +38,8 @@ int main(int argc, char *argv[]) PROG_NAME = argv[0]; if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "help"))) { - show_usage(); - return 1; + show_usage(stdout); + return 0; } if (argc == 1) { @@ -61,6 +62,6 @@ findsubcommand: } fprintf(stderr, "Invalid subcommand: `%s`\n", argv[1]); - show_usage(); + show_usage(stderr); return 1; } |