diff options
-rw-r--r-- | apps/lib/opt.c | 3 | ||||
-rw-r--r-- | apps/openssl.c | 14 | ||||
-rw-r--r-- | test/recipes/20-test_app.t | 10 |
3 files changed, 19 insertions, 8 deletions
diff --git a/apps/lib/opt.c b/apps/lib/opt.c index 5ddf1c7a74..22d4138301 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 0c95a7585e..b61ed5f81d 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 e7246565f2..dfd0db25b8 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"); |