Skip to content

Commit

Permalink
Add support for --version and synonyms
Browse files Browse the repository at this point in the history
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 #20936)
  • Loading branch information
IDisposable authored and paulidale committed May 18, 2023
1 parent 219db5e commit 831ef53
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
22 changes: 16 additions & 6 deletions apps/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
{
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -326,7 +337,6 @@ const OPTIONS help_options[] = {
{NULL}
};


int help_main(int argc, char **argv)
{
FUNCTION *fp;
Expand Down
24 changes: 23 additions & 1 deletion doc/man1/openssl.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<-->
Expand Down
8 changes: 7 additions & 1 deletion test/recipes/20-test_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");

0 comments on commit 831ef53

Please sign in to comment.