zed: untangle -h option listing

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #11860
This commit is contained in:
наб 2021-04-07 15:20:22 +02:00 committed by Brian Behlendorf
parent 52f65648e0
commit 5a674a1b42
1 changed files with 40 additions and 32 deletions

View File

@ -128,42 +128,50 @@ zed_conf_destroy(struct zed_conf *zcp)
static void static void
_zed_conf_display_help(const char *prog, int got_err) _zed_conf_display_help(const char *prog, int got_err)
{ {
struct opt { const char *o, *d, *v; };
FILE *fp = got_err ? stderr : stdout; FILE *fp = got_err ? stderr : stdout;
int w1 = 4; /* width of leading whitespace */
int w2 = 8; /* width of L-justified option field */ struct opt *oo;
struct opt iopts[] = {
{ .o = "-h", .d = "Display help" },
{ .o = "-L", .d = "Display license information" },
{ .o = "-V", .d = "Display version information" },
{},
};
struct opt nopts[] = {
{ .o = "-v", .d = "Be verbose" },
{ .o = "-f", .d = "Force daemon to run" },
{ .o = "-F", .d = "Run daemon in the foreground" },
{ .o = "-I",
.d = "Idle daemon until kernel module is (re)loaded" },
{ .o = "-M", .d = "Lock all pages in memory" },
{ .o = "-P", .d = "$PATH for ZED to use (only used by ZTS)" },
{ .o = "-Z", .d = "Zero state file" },
{},
};
struct opt vopts[] = {
{ .o = "-d DIR", .d = "Read enabled ZEDLETs from DIR.",
.v = ZED_ZEDLET_DIR },
{ .o = "-p FILE", .d = "Write daemon's PID to FILE.",
.v = ZED_PID_FILE },
{ .o = "-s FILE", .d = "Write daemon's state to FILE.",
.v = ZED_STATE_FILE },
{ .o = "-j JOBS", .d = "Start at most JOBS at once.",
.v = "16" },
{},
};
fprintf(fp, "Usage: %s [OPTION]...\n", (prog ? prog : "zed")); fprintf(fp, "Usage: %s [OPTION]...\n", (prog ? prog : "zed"));
fprintf(fp, "\n"); fprintf(fp, "\n");
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-h", for (oo = iopts; oo->o; ++oo)
"Display help."); fprintf(fp, " %*s %s\n", -8, oo->o, oo->d);
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-L",
"Display license information.");
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-V",
"Display version information.");
fprintf(fp, "\n"); fprintf(fp, "\n");
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-v", for (oo = nopts; oo->o; ++oo)
"Be verbose."); fprintf(fp, " %*s %s\n", -8, oo->o, oo->d);
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-f",
"Force daemon to run.");
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-F",
"Run daemon in the foreground.");
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-I",
"Idle daemon until kernel module is (re)loaded.");
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-M",
"Lock all pages in memory.");
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-P",
"$PATH for ZED to use (only used by ZTS).");
fprintf(fp, "%*c%*s %s\n", w1, 0x20, -w2, "-Z",
"Zero state file.");
fprintf(fp, "\n"); fprintf(fp, "\n");
fprintf(fp, "%*c%*s %s [%s]\n", w1, 0x20, -w2, "-d DIR", for (oo = vopts; oo->o; ++oo)
"Read enabled ZEDLETs from DIR.", ZED_ZEDLET_DIR); fprintf(fp, " %*s %s [%s]\n", -8, oo->o, oo->d, oo->v);
fprintf(fp, "%*c%*s %s [%s]\n", w1, 0x20, -w2, "-p FILE",
"Write daemon's PID to FILE.", ZED_PID_FILE);
fprintf(fp, "%*c%*s %s [%s]\n", w1, 0x20, -w2, "-s FILE",
"Write daemon's state to FILE.", ZED_STATE_FILE);
fprintf(fp, "%*c%*s %s [%d]\n", w1, 0x20, -w2, "-j JOBS",
"Start at most JOBS at once.", 16);
fprintf(fp, "\n"); fprintf(fp, "\n");
exit(got_err ? EXIT_FAILURE : EXIT_SUCCESS); exit(got_err ? EXIT_FAILURE : EXIT_SUCCESS);
@ -303,8 +311,8 @@ zed_conf_parse_opts(struct zed_conf *zcp, int argc, char **argv)
if (optopt == '?') if (optopt == '?')
_zed_conf_display_help(argv[0], EXIT_SUCCESS); _zed_conf_display_help(argv[0], EXIT_SUCCESS);
fprintf(stderr, "%s: %s '-%c'\n\n", argv[0], fprintf(stderr, "%s: Invalid option '-%c'\n\n",
"Invalid option", optopt); argv[0], optopt);
_zed_conf_display_help(argv[0], EXIT_FAILURE); _zed_conf_display_help(argv[0], EXIT_FAILURE);
break; break;
} }