zpool/zfs: accept --help and -? after a subcommand

Print the short usage instead of "invalid option".

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Christos Longros <chris.longros@gmail.com>
Closes #18541
This commit is contained in:
Christos Longros
2026-06-04 22:39:00 +02:00
committed by GitHub
parent 5fea0c838a
commit a65ed7afd3
2 changed files with 24 additions and 0 deletions
+12
View File
@@ -9399,6 +9399,18 @@ main(int argc, char **argv)
return (1);
}
/*
* Special case '<subcommand> --help|-?'
*/
if (argc >= 3 && (strcmp(argv[2], "--help") == 0 ||
strcmp(argv[2], "-?") == 0)) {
int idx;
if (find_command_idx(cmdname, &idx) == 0) {
current_command = &command_table[idx];
usage(B_FALSE);
}
}
zfs_save_arguments(argc, argv, history_str, sizeof (history_str));
libzfs_print_on_error(g_zfs, B_TRUE);
+12
View File
@@ -13878,6 +13878,18 @@ main(int argc, char **argv)
if (strcmp(cmdname, "help") == 0)
return (zpool_do_help(argc, argv));
/*
* Special case '<subcommand> --help|-?'
*/
if (argc >= 3 && (strcmp(argv[2], "--help") == 0 ||
strcmp(argv[2], "-?") == 0)) {
int idx;
if (find_command_idx(cmdname, &idx) == 0) {
current_command = &command_table[idx];
usage(B_FALSE);
}
}
if ((g_zfs = libzfs_init()) == NULL) {
(void) fprintf(stderr, "%s\n", libzfs_error_init(errno));
return (1);