diff options
-rw-r--r-- | apps/openssl.c | 22 | ||||
-rw-r--r-- | doc/man1/openssl.pod | 24 | ||||
-rw-r--r-- | test/recipes/20-test_app.t | 8 |
3 files changed, 46 insertions, 8 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; diff --git a/doc/man1/openssl.pod b/doc/man1/openssl.pod index 9bfd2f88a8..3d185bdc27 100644 --- a/doc/man1/openssl.pod +++ b/doc/man1/openssl.pod @@ -13,6 +13,8 @@ I<command> B<openssl> B<no->I<XXX> [ I<options> ] +B<openssl> 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<openssl> program version. +For more detailed information see L<openssl-version(1)>. +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 be79b37750..2560b20fc4 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"); |