From d4fdb249f234dcd9daed181d57eff5a3812e9316 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sun, 2 Dec 2018 23:13:12 +0000 Subject: [PATCH] Usage cleanup pt 2 Eliminage redundant spaces and nvmecontrol at start of all the usage strings. Update the usage printing code to add them back when presenting to the user. Allow multi-line usage messages and print proper leading spaces for lines starting with a space. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D18403 --- sbin/nvmecontrol/devlist.c | 2 +- sbin/nvmecontrol/firmware.c | 2 +- sbin/nvmecontrol/format.c | 2 +- sbin/nvmecontrol/identify.c | 2 +- sbin/nvmecontrol/logpage.c | 2 +- sbin/nvmecontrol/ns.c | 12 ++++++------ sbin/nvmecontrol/nvmecontrol.c | 19 ++++++++++++++++++- sbin/nvmecontrol/perftest.c | 8 ++++---- sbin/nvmecontrol/power.c | 2 +- sbin/nvmecontrol/reset.c | 2 +- sbin/nvmecontrol/wdc.c | 4 ++-- 11 files changed, 37 insertions(+), 20 deletions(-) diff --git a/sbin/nvmecontrol/devlist.c b/sbin/nvmecontrol/devlist.c index f0dfb1b304d..ab8527f2946 100644 --- a/sbin/nvmecontrol/devlist.c +++ b/sbin/nvmecontrol/devlist.c @@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" #define DEVLIST_USAGE \ -" nvmecontrol devlist\n" + "devlist\n" static inline uint32_t ns_get_sector_size(struct nvme_namespace_data *nsdata) diff --git a/sbin/nvmecontrol/firmware.c b/sbin/nvmecontrol/firmware.c index ecec3cc0b8c..7dc19241c57 100644 --- a/sbin/nvmecontrol/firmware.c +++ b/sbin/nvmecontrol/firmware.c @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" #define FIRMWARE_USAGE \ -" nvmecontrol firmware [-s slot] [-f path_to_firmware] [-a] \n" + "firmware [-s slot] [-f path_to_firmware] [-a] \n" static int slot_has_valid_firmware(int fd, int slot) diff --git a/sbin/nvmecontrol/format.c b/sbin/nvmecontrol/format.c index af8e40f8472..50cd659c7f1 100644 --- a/sbin/nvmecontrol/format.c +++ b/sbin/nvmecontrol/format.c @@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" #define FORMAT_USAGE \ -" nvmecontrol format [-f fmt] [-m mset] [-p pi] [-l pil] [-E] [-C] \n" + "format [-f fmt] [-m mset] [-p pi] [-l pil] [-E] [-C] \n" static void format(struct nvme_function *nf, int argc, char *argv[]) diff --git a/sbin/nvmecontrol/identify.c b/sbin/nvmecontrol/identify.c index 487bdbfc6a1..04f46cce505 100644 --- a/sbin/nvmecontrol/identify.c +++ b/sbin/nvmecontrol/identify.c @@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol_ext.h" #define IDENTIFY_USAGE \ -" nvmecontrol identify [-x [-v]] \n" + "identify [-x [-v]] \n" static void print_namespace(struct nvme_namespace_data *nsdata) diff --git a/sbin/nvmecontrol/logpage.c b/sbin/nvmecontrol/logpage.c index 421a4a760cc..a6249a6d3f8 100644 --- a/sbin/nvmecontrol/logpage.c +++ b/sbin/nvmecontrol/logpage.c @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$"); SET_DECLARE(logpage, struct logpage_function); #define LOGPAGE_USAGE \ -" nvmecontrol logpage <-p page_id> [-b] [-v vendor] [-x] \n" \ + "logpage <-p page_id> [-b] [-v vendor] [-x] \n" \ #define MAX_FW_SLOTS (7) diff --git a/sbin/nvmecontrol/ns.c b/sbin/nvmecontrol/ns.c index 5cae4b8cd4d..0822aa4b592 100644 --- a/sbin/nvmecontrol/ns.c +++ b/sbin/nvmecontrol/ns.c @@ -43,22 +43,22 @@ __FBSDID("$FreeBSD$"); SET_DECLARE(ns, struct nvme_function); -#define NS_USAGE \ -" nvmecontrol ns (create|delete|attach|detach)\n" +#define NS_USAGE \ + "ns (create|delete|attach|detach)\n" /* handles NVME_OPC_NAMESPACE_MANAGEMENT and ATTACHMENT admin cmds */ #define NSCREATE_USAGE \ -" nvmecontrol ns create -s size [-c cap] [-f fmt] [-m mset] [-n nmic] [-p pi] [-l pil] nvmeN\n" + "ns create -s size [-c cap] [-f fmt] [-m mset] [-n nmic] [-p pi] [-l pil] nvmeN\n" #define NSDELETE_USAGE \ -" nvmecontrol ns delete -n nsid nvmeN\n" + "ns delete -n nsid nvmeN\n" #define NSATTACH_USAGE \ -" nvmecontrol ns attach -n nsid [-c ctrlrid] nvmeN \n" + "ns attach -n nsid [-c ctrlrid] nvmeN \n" #define NSDETACH_USAGE \ -" nvmecontrol ns detach -n nsid [-c ctrlrid] nvmeN\n" + "ns detach -n nsid [-c ctrlrid] nvmeN\n" void nscreate(struct nvme_function *nf, int argc, char *argv[]); void nsdelete(struct nvme_function *nf, int argc, char *argv[]); diff --git a/sbin/nvmecontrol/nvmecontrol.c b/sbin/nvmecontrol/nvmecontrol.c index 16e79ae528e..bda92b45533 100644 --- a/sbin/nvmecontrol/nvmecontrol.c +++ b/sbin/nvmecontrol/nvmecontrol.c @@ -52,7 +52,24 @@ SET_DECLARE(top, struct nvme_function); static void print_usage(const struct nvme_function *f) { - fprintf(stderr, "%s", f->usage); + const char *cp; + char ch; + bool need_prefix = true; + + cp = f->usage; + while (*cp) { + ch = *cp++; + if (need_prefix) { + if (ch != ' ') + fputs(" nvmecontrol ", stderr); + else + fputs(" ", stderr); + } + fputc(ch, stderr); + need_prefix = (ch == '\n'); + } + if (!need_prefix) + fputc('\n', stderr); } static void diff --git a/sbin/nvmecontrol/perftest.c b/sbin/nvmecontrol/perftest.c index 16b536dba6a..9d15f1ee9d0 100644 --- a/sbin/nvmecontrol/perftest.c +++ b/sbin/nvmecontrol/perftest.c @@ -46,10 +46,10 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" #define PERFTEST_USAGE \ -" nvmecontrol perftest <-n num_threads> <-o read|write>\n" \ -" <-s size_in_bytes> <-t time_in_seconds>\n" \ -" <-i intr|wait> [-f refthread] [-p]\n" \ -" \n" + "perftest <-n num_threads> <-o read|write>\n" \ + " <-s size_in_bytes> <-t time_in_seconds>\n" \ + " <-i intr|wait> [-f refthread] [-p]\n" \ + " \n" static void print_perftest(struct nvme_io_test *io_test, bool perthread) diff --git a/sbin/nvmecontrol/power.c b/sbin/nvmecontrol/power.c index fae33a8b3a1..0bd706ba17d 100644 --- a/sbin/nvmecontrol/power.c +++ b/sbin/nvmecontrol/power.c @@ -45,7 +45,7 @@ _Static_assert(sizeof(struct nvme_power_state) == 256 / NBBY, "nvme_power_state size wrong"); #define POWER_USAGE \ -" nvmecontrol power [-l] [-p new-state [-w workload-hint]] \n" + "power [-l] [-p new-state [-w workload-hint]] \n" static void power_list_one(int i, struct nvme_power_state *nps) diff --git a/sbin/nvmecontrol/reset.c b/sbin/nvmecontrol/reset.c index 4369c417f10..27b9e69ccc8 100644 --- a/sbin/nvmecontrol/reset.c +++ b/sbin/nvmecontrol/reset.c @@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" #define RESET_USAGE \ -" nvmecontrol reset \n" + "reset \n" static void reset(struct nvme_function *nf, int argc, char *argv[]) diff --git a/sbin/nvmecontrol/wdc.c b/sbin/nvmecontrol/wdc.c index ebe3b342a9a..dc932e6214d 100644 --- a/sbin/nvmecontrol/wdc.c +++ b/sbin/nvmecontrol/wdc.c @@ -43,7 +43,7 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" #define WDC_USAGE \ -" nvmecontrol wdc (cap-diag|drive-log|get-crash-dump|purge|purge-montior)\n" + "wdc (cap-diag)\n" SET_DECLARE(wdc, struct nvme_function); @@ -54,7 +54,7 @@ SET_DECLARE(wdc, struct nvme_function); static void wdc_cap_diag(struct nvme_function *nf, int argc, char *argv[]); -#define WDC_CAP_DIAG_USAGE "\tnvmecontrol wdc cap-diag [-o path-template]\n" +#define WDC_CAP_DIAG_USAGE "wdc cap-diag [-o path-template]\n" NVME_COMMAND(wdc, cap-diag, wdc_cap_diag, WDC_CAP_DIAG_USAGE);