From: Chengwen Feng <fengchengwen@huawei.com>
To: <dev@dpdk.org>, <thomas@monjalon.net>, <ferruh.yigit@amd.com>,
<stephen@networkplumber.org>
Cc: <tangkunshan@huawei.com>
Subject: [PATCH v3 7/8] argparse: pretty help info
Date: Fri, 26 Jan 2024 06:10:12 +0000 [thread overview]
Message-ID: <20240126061013.53608-8-fengchengwen@huawei.com> (raw)
In-Reply-To: <20240126061013.53608-1-fengchengwen@huawei.com>
This commit aligns help info.
Take dmafwd as an example, previous:
options:
-h, --help: show this help message and exit.
--mac-updating: Enable MAC addresses updating
--no-mac-updating: Disable MAC addresses updating
-p, --portmask: hexadecimal bitmask of ports to configure
-q, --nb-queue: number of RX queues per port (default is 1)
-c, --copy-type: type of copy: sw|hw
-s, --ring-size: size of dmadev descriptor ring for hardware copy mode or rte_ring for software copy mode
-b, --dma-batch-size: number of requests per DMA batch
-f, --max-frame-size: max frame size
-m, --force-min-copy-size: force a minimum copy length, even for smaller packets
-i, --stats-interval: interval, in seconds, between stats prints (default is 1)
Now:
options:
-h, --help show this help message and exit.
--mac-updating Enable MAC addresses updating
--no-mac-updating Disable MAC addresses updating
-p, --portmask hexadecimal bitmask of ports to configure
-q, --nb-queue number of RX queues per port (default is 1)
-c, --copy-type type of copy: sw|hw
-s, --ring-size size of dmadev descriptor ring for hardware copy mode or rte_ring for software copy mode
-b, --dma-batch-size number of requests per DMA batch
-f, --max-frame-size max frame size
-m, --force-min-copy-size force a minimum copy length, even for smaller packets
-i, --stats-interval interval, in seconds, between stats prints (default is 1)
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/argparse/rte_argparse.c | 67 +++++++++++++++++++++++++++++++------
1 file changed, 56 insertions(+), 11 deletions(-)
diff --git a/lib/argparse/rte_argparse.c b/lib/argparse/rte_argparse.c
index 4b10f3e519..2d953f1694 100644
--- a/lib/argparse/rte_argparse.c
+++ b/lib/argparse/rte_argparse.c
@@ -640,8 +640,47 @@ parse_args(struct rte_argparse *obj, int argc, char **argv, bool *show_help)
return 0;
}
+static uint32_t
+calc_help_align(const struct rte_argparse *obj)
+{
+ const struct rte_argparse_arg *arg;
+ uint32_t width = 12; /* Default "-h, --help " len. */
+ uint32_t len;
+ uint32_t i;
+
+ for (i = 0; /* NULL */; i++) {
+ arg = &obj->args[i];
+ if (arg->name_long == NULL)
+ break;
+ len = strlen(arg->name_long);
+ if (is_arg_optional(arg) && arg->name_short != NULL) {
+ len += strlen(", ");
+ len += strlen(arg->name_short);
+ }
+ width = RTE_MAX(width, 1 + len + 2); /* start with 1 & end with 2 space. */
+ }
+
+ return width;
+}
+
+static void
+show_oneline_help(const struct rte_argparse_arg *arg, uint32_t width)
+{
+ uint32_t len = 0;
+ uint32_t i;
+
+ if (arg->name_short != NULL)
+ len = printf(" %s,", arg->name_short);
+ len += printf(" %s", arg->name_long);
+
+ for (i = len; i < width; i++)
+ printf(" ");
+
+ printf("%s\n", arg->help);
+}
+
static void
-show_args_pos_help(const struct rte_argparse *obj)
+show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
{
uint32_t position_count = calc_position_count(obj);
const struct rte_argparse_arg *arg;
@@ -657,43 +696,49 @@ show_args_pos_help(const struct rte_argparse *obj)
break;
if (!is_arg_positional(arg))
continue;
- printf(" %s: %s\n", arg->name_long, arg->help);
+ show_oneline_help(arg, align);
}
}
static void
-show_args_opt_help(const struct rte_argparse *obj)
+show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
{
+ static const struct rte_argparse_arg help = {
+ .name_long = "--help",
+ .name_short = "-h",
+ .help = "show this help message and exit.",
+ };
const struct rte_argparse_arg *arg;
uint32_t i;
- printf("\noptions:\n"
- " -h, --help: show this help message and exit.\n");
+ printf("\noptions:\n");
+ show_oneline_help(&help, align);
for (i = 0; /* NULL */; i++) {
arg = &obj->args[i];
if (arg->name_long == NULL)
break;
if (!is_arg_optional(arg))
continue;
- if (arg->name_short != NULL)
- printf(" %s, %s: %s\n", arg->name_short, arg->name_long, arg->help);
- else
- printf(" %s: %s\n", arg->name_long, arg->help);
+ show_oneline_help(arg, align);
}
}
static void
show_args_help(const struct rte_argparse *obj)
{
+ uint32_t align = calc_help_align(obj);
+
printf("usage: %s %s\n", obj->prog_name, obj->usage);
if (obj->descriptor != NULL)
printf("\ndescriptor: %s\n", obj->descriptor);
- show_args_pos_help(obj);
- show_args_opt_help(obj);
+ show_args_pos_help(obj, align);
+ show_args_opt_help(obj, align);
if (obj->epilog != NULL)
printf("\n%s\n", obj->epilog);
+ else
+ printf("\n");
}
int
--
2.17.1
next prev parent reply other threads:[~2024-01-26 6:15 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-21 12:26 [24.03 RFC] argparse: add argparse library Chengwen Feng
2023-11-21 16:36 ` Stephen Hemminger
2023-11-22 6:28 ` fengchengwen
2023-12-04 7:50 ` [RFC v2 0/6] " Chengwen Feng
2023-12-04 7:50 ` [RFC v2 1/6] argparse: " Chengwen Feng
2023-12-04 17:10 ` Stephen Hemminger
2023-12-05 1:22 ` fengchengwen
2023-12-04 7:50 ` [RFC v2 2/6] argparse: support verify argument config Chengwen Feng
2023-12-04 7:50 ` [RFC v2 3/6] test/argparse: add verify argument config test Chengwen Feng
2023-12-04 7:50 ` [RFC v2 4/6] argparse: support parse parameters Chengwen Feng
2023-12-04 7:50 ` [RFC v2 5/6] test/argparse: add parse parameters test Chengwen Feng
2023-12-04 7:50 ` [RFC v2 6/6] examples/dma: replace getopt with argparse Chengwen Feng
2023-12-11 9:50 ` [RFC v3 00/12] add argparse library Chengwen Feng
2023-12-11 9:50 ` [RFC v3 01/12] eal: introduce more macro for bit definition Chengwen Feng
2023-12-11 9:51 ` [RFC v3 02/12] argparse: add argparse library Chengwen Feng
2023-12-11 9:51 ` [RFC v3 03/12] argparse: support verify argument config Chengwen Feng
2023-12-11 9:51 ` [RFC v3 04/12] test/argparse: add verify argument config test Chengwen Feng
2023-12-11 9:51 ` [RFC v3 05/12] argparse: support parse parameters Chengwen Feng
2023-12-11 9:51 ` [RFC v3 06/12] test/argparse: add parse parameters test Chengwen Feng
2023-12-11 9:51 ` [RFC v3 07/12] argparse: provide parsing known type API Chengwen Feng
2023-12-11 9:51 ` [RFC v3 08/12] test/argparse: add parse type test Chengwen Feng
2023-12-11 9:51 ` [RFC v3 09/12] argparse: support parse unsigned base type Chengwen Feng
2023-12-11 9:51 ` [RFC v3 10/12] test/argparse: add parse unsigned base type test Chengwen Feng
2023-12-11 9:51 ` [RFC v3 11/12] argparse: pretty help info Chengwen Feng
2023-12-11 9:51 ` [RFC v3 12/12] examples/dma: replace getopt with argparse Chengwen Feng
2024-01-22 3:57 ` [PATCH 00/12] add argparse library Chengwen Feng
2024-01-22 3:57 ` [PATCH 01/12] eal: introduce more macro for bit definition Chengwen Feng
2024-01-24 13:00 ` Thomas Monjalon
2024-01-22 3:57 ` [PATCH 02/12] argparse: add argparse library Chengwen Feng
2024-01-22 4:54 ` Stephen Hemminger
2024-01-22 6:06 ` fengchengwen
2024-01-24 13:24 ` Thomas Monjalon
2024-01-25 3:44 ` fengchengwen
2024-01-22 3:57 ` [PATCH 03/12] argparse: support verify argument config Chengwen Feng
2024-01-22 3:57 ` [PATCH 04/12] test/argparse: add verify argument config test Chengwen Feng
2024-01-24 13:01 ` Thomas Monjalon
2024-01-22 3:57 ` [PATCH 05/12] argparse: support parse parameters Chengwen Feng
2024-01-22 3:57 ` [PATCH 06/12] test/argparse: add parse parameters test Chengwen Feng
2024-01-22 3:57 ` [PATCH 07/12] argparse: provide parsing known type API Chengwen Feng
2024-01-22 3:57 ` [PATCH 08/12] test/argparse: add parse type test Chengwen Feng
2024-01-22 3:57 ` [PATCH 09/12] argparse: support parse unsigned base type Chengwen Feng
2024-01-22 3:58 ` [PATCH 10/12] test/argparse: add parse unsigned base type test Chengwen Feng
2024-01-22 3:58 ` [PATCH 11/12] argparse: pretty help info Chengwen Feng
2024-01-22 3:58 ` [PATCH 12/12] examples/dma: replace getopt with argparse Chengwen Feng
2024-01-24 13:26 ` Thomas Monjalon
2024-01-24 15:54 ` [24.03 RFC] argparse: add argparse library Stephen Hemminger
2024-01-25 6:31 ` fengchengwen
2024-01-26 16:38 ` Stephen Hemminger
2024-01-25 11:52 ` [PATCH v2 0/8] " Chengwen Feng
2024-01-25 11:52 ` [PATCH v2 1/8] eal: introduce more macro for bit definition Chengwen Feng
2024-01-25 11:52 ` [PATCH v2 2/8] argparse: add argparse library Chengwen Feng
2024-01-25 11:52 ` [PATCH v2 3/8] argparse: support verify argument config Chengwen Feng
2024-01-25 11:52 ` [PATCH v2 4/8] argparse: support parse parameters Chengwen Feng
2024-01-25 11:52 ` [PATCH v2 5/8] argparse: provide parsing known type API Chengwen Feng
2024-01-25 11:52 ` [PATCH v2 6/8] argparse: support parse unsigned base type Chengwen Feng
2024-01-25 11:52 ` [PATCH v2 7/8] argparse: pretty help info Chengwen Feng
2024-01-25 11:52 ` [PATCH v2 8/8] examples/dma: replace getopt with argparse Chengwen Feng
2024-01-26 6:10 ` [PATCH v3 0/8] add argparse library Chengwen Feng
2024-01-26 6:10 ` [PATCH v3 1/8] eal: introduce more macro for bit definition Chengwen Feng
2024-01-26 6:10 ` [PATCH v3 2/8] argparse: add argparse library Chengwen Feng
2024-01-26 6:10 ` [PATCH v3 3/8] argparse: support verify argument config Chengwen Feng
2024-01-26 6:10 ` [PATCH v3 4/8] argparse: support parse parameters Chengwen Feng
2024-01-26 6:10 ` [PATCH v3 5/8] argparse: provide parsing known type API Chengwen Feng
2024-01-26 6:10 ` [PATCH v3 6/8] argparse: support parse unsigned base type Chengwen Feng
2024-01-26 6:10 ` Chengwen Feng [this message]
2024-01-26 6:10 ` [PATCH v3 8/8] examples/dma: replace getopt with argparse Chengwen Feng
2024-02-14 16:53 ` [PATCH v3 0/8] add argparse library Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240126061013.53608-8-fengchengwen@huawei.com \
--to=fengchengwen@huawei.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=stephen@networkplumber.org \
--cc=tangkunshan@huawei.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).