diff options
author | Marc Brooks <IDisposable@gmail.com> | 2023-05-10 17:48:00 -0500 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-05-18 17:18:10 +1000 |
commit | 831ef5347253a9381c2ab6bd3ca74cbe10995939 (patch) | |
tree | 6409af018ebb7314294c9bf1d940733bd8fcb2c6 /apps | |
parent | 219db5e43c4f030a1c9c4a2f28249fd89b05ea0d (diff) | |
download | openssl-831ef5347253a9381c2ab6bd3ca74cbe10995939.tar.gz |
Add support for --version and synonyms
Just like --help is explicitly supported, we should support --version.
This will greatly ease people adopting openssl.
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20936)
Diffstat (limited to 'apps')
-rw-r--r-- | apps/openssl.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/apps/openssl.c b/apps/openssl.c index f5ee1476ff..87f004d320 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -232,6 +232,7 @@ static void setup_trace(const char *str) #endif /* OPENSSL_NO_TRACE */ static char *help_argv[] = { "help", NULL }; +static char *version_argv[] = { "version", NULL }; int main(int argc, char *argv[]) { @@ -241,6 +242,7 @@ int main(int argc, char *argv[]) const char *fname; ARGS arg; int global_help = 0; + int global_version = 0; int ret = 0; arg.argv = NULL; @@ -285,17 +287,26 @@ int main(int argc, char *argv[]) global_help = argc > 1 && (strcmp(argv[1], "-help") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--h") == 0); + global_version = argc > 1 + && (strcmp(argv[1], "-version") == 0 || strcmp(argv[1], "--version") == 0 + || strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--v") == 0); + argc--; argv++; - opt_appname(argc == 1 || global_help ? "help" : argv[0]); + opt_appname(argc == 1 || global_help ? "help" : global_version ? "version" : argv[0]); } else { argv[0] = pname; } - /* If there's a command, run with that, otherwise "help". */ - ret = argc == 0 || global_help - ? do_cmd(prog, 1, help_argv) - : do_cmd(prog, argc, argv); + /* + * If there's no command, assume "help". If there's an override for help + * or version run those, otherwise run the command given. + */ + ret = (argc == 0) || global_help + ? do_cmd(prog, 1, help_argv) + : global_version + ? do_cmd(prog, 1, version_argv) + : do_cmd(prog, argc, argv); end: OPENSSL_free(default_config_file); @@ -326,7 +337,6 @@ const OPTIONS help_options[] = { {NULL} }; - int help_main(int argc, char **argv) { FUNCTION *fp; |