APPS: Print help also on -h and --h; print high-level help when no cmd given

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13799)
This commit is contained in:
Dr. David von Oheimb 2021-01-07 10:16:12 +01:00 committed by Dr. David von Oheimb
parent 3372039252
commit 678cae0295
3 changed files with 19 additions and 8 deletions

View File

@ -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. */

View File

@ -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);

View File

@ -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");