From: fengchengwen <fengchengwen@huawei.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: <dev@dpdk.org>, <thomas@monjalon.net>, <ferruh.yigit@amd.com>
Subject: Re: [24.03 RFC] argparse: add argparse library
Date: Wed, 22 Nov 2023 14:28:09 +0800 [thread overview]
Message-ID: <ca4d8300-9435-3455-bb72-519b17e19218@huawei.com> (raw)
In-Reply-To: <20231121083624.5dd009b8@hermes.local>
Hi Stephen,
On 2023/11/22 0:36, Stephen Hemminger wrote:
> On Tue, 21 Nov 2023 12:26:51 +0000
> Chengwen Feng <fengchengwen@huawei.com> wrote:
>
>> Introduce argparse library (which was inspired by the thread [1]),
>> compared with getopt, the argparse has following advantages:
>> 1) Set the help information when defining parameters.
>> 2) Support positional parameters.
>>
>> The parameters parsing according following:
>> 1) positional: use callback to parse (passed the long-name as the key
>> for callback).
>> 2) optional:
>> In addition to callback to parse, but also support:
>> 2.1) no-val: support set default value to saver.
>> 2.2) has-val: support set value to saver, the value must be conform
>> RTE_ARGPARSE_ARG_VAL_xxx.
>> 2.3) opt-val: if current without value then treat as no-val, else could
>> treat as has-val.
>>
>> Examples: (take dmafwd as example):
>> 1) If parse with callback:
>> static int
>> func(const char *key, const char *value, const char *opaque)
>> {
>> if (!strcmp("--mac-updating", key)) {
>> mac_updating = 1;
>> } else if (!strcmp("--no-mac-updating", key)) {
>> mac_updating = 0;
>> } else if (!strcmp("--portmask", key)) {
>> dma_enabled_port_mask = dma_parse_portmask(optarg);
>> if (dma_enabled_port_mask & ~default_port_mask ||
>> dma_enabled_port_mask <= 0) {
>> ...
>> }
>> } else {
>> ...
>> }
>> }
>>
>> static int
>> dma_parse_args(int argc, char **argv, unsigned int nb_ports)
>> {
>> static struct rte_argparse opts[] = {
>> .prog = "dma",
>> .usage = NULL,
>> .descriptor = "dma and nic fwd example",
>> .epilog = NULL,
>> .exit_on_error = true,
>> .opt = {
>> { "--mac-updating", NULL, "Enable MAC addresses updating", func, 0, NULL, NULL, RTE_ARGPARSE_ARG_NO_VAL },
>> { "--no-mac-updating", NULL, "disable MAC addresses updating", func, 0, NULL, NULL, RTE_ARGPARSE_ARG_NO_VAL },
>> { "--portmask", "-p", "hexadecimal bitmask of ports to configure", func, 0, NULL, NULL, RTE_ARGPARSE_ARG_HAS_VAL },
>> { NULL, NULL, NULL, NULL, 0, NULL, NULL, 0}
>> }
>> };
>> return rte_argparse_parse(opts, argc, argv);
>> }
>>
>> 2) If parse with value:
>> static int
>> dma_parse_args(int argc, char **argv, unsigned int nb_ports)
>> {
>> static struct rte_argparse opts[] = {
>> .prog = "dma",
>> .usage = NULL,
>> .descriptor = "dma and nic fwd example",
>> .epilog = NULL,
>> .exit_on_error = true,
>> .opt = {
>> { "--mac-updating", NULL, "Enable MAC addresses updating", NULL, 0, &mac_updating, (void *)1, RTE_ARGPARSE_ARG_NO_VAL },
>> { "--no-mac-updating", NULL, "disable MAC addresses updating", NULL, 0, &mac_updating, (void *)0, RTE_ARGPARSE_ARG_NO_VAL },
>> { "--portmask", "-p", "hexadecimal bitmask of ports to configure", NULL, 0, &dma_enabled_port_mask, NULL, RTE_ARGPARSE_ARG_HAS_VAL },
>> { NULL, NULL, NULL, NULL, 0, NULL, NULL, 0}
>> }
>> };
>> int ret;
>> ret = rte_argparse_parse(opts, argc, argv);
>> if (ret != 0)
>> return ret;
>> if (dma_enabled_port_mask & ~default_port_mask ||
>> dma_enabled_port_mask <= 0) {
>> ...
>> }
>> }
>>
>> 3) Also could mix parse with func and with value.
>>
>> [1] https://patchwork.dpdk.org/project/dpdk/patch/20231105054539.22303-2-fengchengwen@huawei.com/
>>
>> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
>> ---
>
> Need tests and more detailed man page.
> Maybe convert one of the existing examples.
Should add now ?
I prefer wait TB decide to accept it before starting it.
>
> Can it be used in nested fashion for kvargs?
I planed to use kvargs inner to implement the argparse library.
> The existing kvargs syntax is awkward, would be nice to fix/change that but would
> cause lots of arguments :-)
Yes, I try to fix/change by two different ways but no progress:
1) fix the wrong usage, which involve many drivers.
2) add one new API.
Maybe we should keep kvargs as it is.
>
> .
>
next prev parent reply other threads:[~2023-11-22 6:28 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-21 12:26 Chengwen Feng
2023-11-21 16:36 ` Stephen Hemminger
2023-11-22 6:28 ` fengchengwen [this message]
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 ` [PATCH v3 7/8] argparse: pretty help info Chengwen Feng
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=ca4d8300-9435-3455-bb72-519b17e19218@huawei.com \
--to=fengchengwen@huawei.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=stephen@networkplumber.org \
--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).