[RFC v2 1/6] argparse: add argparse library

fengchengwen fengchengwen at huawei.com
Tue Dec 5 02:22:20 CET 2023


Hi Stephen,

On 2023/12/5 1:10, Stephen Hemminger wrote:
> On Mon, 4 Dec 2023 07:50:43 +0000
> Chengwen Feng <fengchengwen at huawei.com> wrote:
> 
>> +   static struct rte_argparse obj = {
>> +      .prog_name = "test-demo",
>> +      .usage = "[EAL options] -- [optional parameters] [positional parameters]",
>> +      .descriptor = NULL,
>> +      .epilog = NULL,
>> +      .exit_on_error = true,
>> +      .callback = argparse_user_callback,
>> +      .args = {
>> +         { "--aaa", "-a", "aaa argument", (void *)&aaa_val, (void *)100, RTE_ARGPARSE_ARG_NO_VALUE       | RTE_ARGPARSE_ARG_VALUE_INT },
>> +         { "--bbb", "-b", "bbb argument", (void *)&bbb_val, NULL,        RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_INT },
>> +         { "--ccc", "-c", "ccc argument", (void *)&ccc_val, (void *)200, RTE_ARGPARSE_ARG_OPTIONAL_VALUE | RTE_ARGPARSE_ARG_VALUE_INT },
>> +         { "--ddd", "-d", "ddd argument", NULL,             (void *)1,   RTE_ARGPARSE_ARG_NO_VALUE       },
>> +         { "--eee", "-e", "eee argument", NULL,             (void *)2,   RTE_ARGPARSE_ARG_REQUIRED_VALUE },
>> +         { "--fff", "-f", "fff argument", NULL,             (void *)3,   RTE_ARGPARSE_ARG_OPTIONAL_VALUE },
>> +         { "ooo",   NULL, "ooo argument", (void *)&ooo_val, NULL,        RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_INT },
>> +         { "ppp",   NULL, "ppp argument", NULL,             (void *)300, RTE_ARGPARSE_ARG_REQUIRED_VALUE },
>> +      },
>> +   };
>> +
> 
> Could the API be made to work with immutable initializers?
> I.e allowing the application to use:
> 	static const struct rte_argparse_obj {

Current impl, it can't be immutable, because the API will modify some reserved bit in args.flags field.

> 
> Also better to just skip the NULL elements here, and use field initializers for the args.

Yes, both are OK.

> That way when structure layout changes, the example will still work.
> Also, pointers do not have to be cast to void * in C code.

OK, will modify in v3.

Thanks

> .
> 


More information about the dev mailing list