Skip to content

Commit

Permalink
Add --version and --help.
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeto committed Mar 6, 2017
1 parent 188a0be commit b218e3b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

/* Compile-time configuration */

#ifndef ENCHIVE_VERSION
# define ENCHIVE_VERSION 1.0
#endif

#ifndef ENCHIVE_RANDOM_DEVICE
# define ENCHIVE_RANDOM_DEVICE /dev/urandom
#endif
Expand Down
7 changes: 6 additions & 1 deletion src/docs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ static const char *docs_usage[] = {
" [-a|--agent[=seconds]] [--no-agent]",
#endif
#if ENCHIVE_OPTION_RANDOM_DEVICE
" [--random-device <file>]",
" [--random-device <file>] "
#else
" "
#endif
"[--version] [--help]",
" <command> [args]",
"",
"Commands (unique prefixes accepted):",
Expand All @@ -24,6 +27,8 @@ static const char *docs_usage[] = {
#endif
" --pubkey <file>, -p set the public key file [~/.enchive.pub]",
" --seckey <file>, -s set the secret key file [~/.enchive.sec]",
" --version display version information",
" --help display this usage information",
"",
"Enchive archives files by encrypting them to yourself using your",
"public key. It uses ChaCha20, Curve25519, and SHA-224.",
Expand Down
16 changes: 16 additions & 0 deletions src/enchive.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,12 @@ print_usage(FILE *f)
multiputs(docs_usage, f);
}

static void
print_version(void)
{
puts("enchive " STR(ENCHIVE_VERSION));
}

int
main(int argc, char **argv)
{
Expand All @@ -1139,6 +1145,8 @@ main(int argc, char **argv)
#endif
{"pubkey", 'p', OPTPARSE_REQUIRED},
{"seckey", 's', OPTPARSE_REQUIRED},
{"version", 'V', OPTPARSE_NONE},
{"help", 'h', OPTPARSE_NONE},
{0, 0, 0}
};

Expand Down Expand Up @@ -1178,6 +1186,14 @@ main(int argc, char **argv)
case 's':
global_seckey = options->optarg;
break;
case 'h':
print_usage(stdout);
exit(EXIT_SUCCESS);
break;
case 'V':
print_version();
exit(EXIT_SUCCESS);
break;
default:
fatal("%s", options->errmsg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sha256.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*********************************************************************
* Filename: sha256.c
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Copyright: Public Domain
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Implementation of the SHA-256 hashing algorithm.
SHA-256 is one of the three algorithms in the SHA2
Expand Down
2 changes: 1 addition & 1 deletion src/sha256.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*********************************************************************
* Filename: sha256.h
* Author: Brad Conte (brad AT bradconte.com)
* Copyright:
* Copyright: Public Domain
* Disclaimer: This code is presented "as is" without any guarantees.
* Details: Defines the API for the corresponding SHA1 implementation.
*********************************************************************/
Expand Down

0 comments on commit b218e3b

Please sign in to comment.