From: Dr. David von Oheimb Date: Thu, 7 Jan 2021 09:16:12 +0000 (+0100) Subject: APPS: Print help also on -h and --h; print high-level help when no cmd given X-Git-Tag: openssl-3.0.0-alpha11~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=678cae0295e3fe600edc049742b8c765a58edebc;p=thirdparty%2Fopenssl.git APPS: Print help also on -h and --h; print high-level help when no cmd given Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/13799) --- diff --git a/apps/lib/opt.c b/apps/lib/opt.c index 5ddf1c7a74d..22d41383014 100644 --- a/apps/lib/opt.c +++ b/apps/lib/opt.c @@ -732,7 +732,8 @@ int opt_next(void) *arg++ = '\0'; for (o = opts; o->name; ++o) { /* If not this option, move on to the next one. */ - if (strcmp(p, o->name) != 0) + if (!(strcmp(p, "h") == 0 && strcmp(o->name, "help") == 0) + && strcmp(p, o->name) != 0) continue; /* If it doesn't take a value, make sure none was given. */ diff --git a/apps/openssl.c b/apps/openssl.c index 0c95a7585ec..b61ed5f81d1 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -237,6 +237,7 @@ int main(int argc, char *argv[]) char *pname; const char *fname; ARGS arg; + int global_help = 0; int ret = 0; arg.argv = NULL; @@ -277,18 +278,21 @@ int main(int argc, char *argv[]) f.name = pname; fp = lh_FUNCTION_retrieve(prog, &f); if (fp == NULL) { - /* We assume we've been called as 'openssl cmd' */ + /* We assume we've been called as 'openssl ...' */ + global_help = argc > 1 + && (strcmp(argv[1], "-help") == 0 || strcmp(argv[1], "--help") == 0 + || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--h") == 0); argc--; argv++; - opt_appname(argv[0]); + opt_appname(argc == 1 || global_help ? "help" : argv[0]); } else { argv[0] = pname; } /* If there's a command, run with that, otherwise "help". */ - ret = argc > 0 - ? do_cmd(prog, argc, argv) - : do_cmd(prog, 1, help_argv); + ret = argc == 0 || global_help + ? do_cmd(prog, 1, help_argv) + : do_cmd(prog, argc, argv); end: OPENSSL_free(default_config_file); diff --git a/test/recipes/20-test_app.t b/test/recipes/20-test_app.t index e7246565f2c..dfd0db25b85 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 => 3; +plan tests => 5; ok(run(app(["openssl"])), "Run openssl app with no args"); @@ -21,5 +21,11 @@ ok(run(app(["openssl"])), ok(run(app(["openssl", "help"])), "Run openssl app with help"); -ok(!run(app(["openssl", "-help"])), +ok(!run(app(["openssl", "-wrong"])), "Run openssl app with incorrect arg"); + +ok(run(app(["openssl", "-help"])), + "Run openssl app with -help"); + +ok(run(app(["openssl", "--help"])), + "Run openssl app with --help");