]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add support for --version and synonyms
authorMarc Brooks <IDisposable@gmail.com>
Wed, 10 May 2023 22:48:00 +0000 (17:48 -0500)
committerPauli <pauli@openssl.org>
Thu, 18 May 2023 07:18:10 +0000 (17:18 +1000)
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)

apps/openssl.c
doc/man1/openssl.pod
test/recipes/20-test_app.t

index f5ee1476ffda5eef975de714b108338d51ff4919..87f004d320721fab1553a13219bd1c6f12ef9aeb 100644 (file)
@@ -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;
index 9bfd2f88a82963e458b8f457bb54c877b72ecac4..3d185bdc272cc5622dae917ef3f157af1749a463 100644 (file)
@@ -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<-->
index be79b377500948901f579fdb5cf3d86ec5ca1c29..2560b20fc45a56d48678d2960d1f34f3a007fda3 100644 (file)
@@ -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");