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 | 742f038fc2d57b15d1539c3cfc7d0c2fe45ac530 (patch) | |
tree | 5713d6b29fb56bb07615cae7d778260627f71cbc /src/wg.c | |
parent | contrib: remove extraneous cruft (diff) | |
download | wireguard-tools-742f038fc2d57b15d1539c3cfc7d0c2fe45ac530.tar.xz wireguard-tools-742f038fc2d57b15d1539c3cfc7d0c2fe45ac530.zip |
wg: improve error reporting and detection
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/wg.c')
-rw-r--r-- | src/wg.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -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; } |