From: Marc Brooks Date: Wed, 10 May 2023 22:48:00 +0000 (-0500) Subject: Add support for --version and synonyms X-Git-Tag: openssl-3.2.0-alpha1~805 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=831ef5347253a9381c2ab6bd3ca74cbe10995939;p=thirdparty%2Fopenssl.git 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 Reviewed-by: Tom Cosgrove Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/20936) --- diff --git a/apps/openssl.c b/apps/openssl.c index f5ee1476ffd..87f004d3207 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; diff --git a/doc/man1/openssl.pod b/doc/man1/openssl.pod index 9bfd2f88a82..3d185bdc272 100644 --- a/doc/man1/openssl.pod +++ b/doc/man1/openssl.pod @@ -13,6 +13,8 @@ I B BI [ I ] +B B<-help> | B<-version> + =head1 DESCRIPTION OpenSSL is a cryptography toolkit implementing the Secure Sockets Layer (SSL) @@ -499,13 +501,33 @@ SM4 Cipher Details of which options are available depend on the specific command. This section describes some common options with common behavior. -=head2 Common Options +=head2 Program Options + +These options can be specified without a command specified to get help +or version information. =over 4 =item B<-help> Provides a terse summary of all options. +For more detailed information, each command supports a B<-help> option. +Accepts B<--help> as well. + +=item B<-version> + +Provides a terse summary of the B program version. +For more detailed information see L. +Accepts B<--version> as well. + +=back + +=head2 Common Options + +=over 4 + +=item B<-help> + If an option takes an argument, the "type" of argument is also given. =item B<--> diff --git a/test/recipes/20-test_app.t b/test/recipes/20-test_app.t index be79b377500..2560b20fc45 100644 --- a/test/recipes/20-test_app.t +++ b/test/recipes/20-test_app.t @@ -13,7 +13,7 @@ use OpenSSL::Test; setup("test_app"); -plan tests => 5; +plan tests => 7; ok(run(app(["openssl"])), "Run openssl app with no args"); @@ -29,3 +29,9 @@ ok(run(app(["openssl", "-help"])), ok(run(app(["openssl", "--help"])), "Run openssl app with --help"); + +ok(run(app(["openssl", "-version"])), + "Run openssl app with -version"); + +ok(run(app(["openssl", "--version"])), + "Run openssl app with --version");