[PATCH v11 05/21] argparse: add documentation on supported value types

fengchengwen fengchengwen at huawei.com
Wed Oct 15 09:53:09 CEST 2025


Minor comment on paragraph layout, with that fixed:
Acked-by: Chengwen Feng <fengchengwen at huawei.com>

On 10/9/2025 9:00 PM, Bruce Richardson wrote:
> The different value types supported by the argparse library are not
> discussed in the documentation, so add some reference material about
> them.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
> ---
>  doc/guides/prog_guide/argparse_lib.rst | 73 +++++++++++++++++++++++++-
>  1 file changed, 71 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/guides/prog_guide/argparse_lib.rst b/doc/guides/prog_guide/argparse_lib.rst
> index b309260d20..7868af5672 100644
> --- a/doc/guides/prog_guide/argparse_lib.rst
> +++ b/doc/guides/prog_guide/argparse_lib.rst
> @@ -160,6 +160,75 @@ both use this way, the parsing is as follows:
>  - For argument ``ooo``, it is positional argument,
>    the ``ooo_val`` will be set to user input's value.
>  
> +Supported Value Types
> +~~~~~~~~~~~~~~~~~~~~~

This paragraph should be the inner paragraph of 'Parsing by autosave way'
I suggest delete the ~~~~~, and move the whole after "Parsing by autosave way"

> +
> +The argparse library supports automatic parsing of several data types when using
> +the autosave method. The parsed values are automatically converted from string
> +input to the appropriate data type and stored in the ``val_saver`` field.
> +
> +Integer Types
> +^^^^^^^^^^^^^
> +
> +The library supports parsing various integer types:
> +
> +- ``RTE_ARGPARSE_VALUE_TYPE_INT`` - signed integer
> +- ``RTE_ARGPARSE_VALUE_TYPE_U8`` - unsigned 8-bit integer
> +- ``RTE_ARGPARSE_VALUE_TYPE_U16`` - unsigned 16-bit integer
> +- ``RTE_ARGPARSE_VALUE_TYPE_U32`` - unsigned 32-bit integer
> +- ``RTE_ARGPARSE_VALUE_TYPE_U64`` - unsigned 64-bit integer
> +
> +.. code-block:: C
> +
> +   static int my_int;
> +   static uint16_t my_port;
> +   static uint32_t my_count;
> +
> +   static struct rte_argparse obj = {
> +      .args = {
> +         { "--number", "-n", "Integer value", &my_int, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_INT },
> +         { "--port", "-p", "Port number", &my_port, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_U16 },
> +         { "--count", "-c", "Count value", &my_count, (void *)1000, RTE_ARGPARSE_VALUE_OPTIONAL, RTE_ARGPARSE_VALUE_TYPE_U32 },
> +         ARGPARSE_ARG_END(),
> +      },
> +   };
> +
> +String Type
> +^^^^^^^^^^^
> +
> +String arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_STR``.
> +When using this type, the input value is saved to the provided pointer without any parsing or validation.
> +
> +.. code-block:: C
> +
> +   static const char *my_string;
> +
> +   static struct rte_argparse obj = {
> +      .args = {
> +         { "--name", "-n", "Name string", &my_string, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_STR },
> +         ARGPARSE_ARG_END(),
> +      },
> +   };
> +
> +Boolean Type
> +^^^^^^^^^^^^
> +
> +Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept the following input formats:
> +
> +- ``true``, ``false`` (case-sensitive)
> +- ``1``, ``0`` (numeric format)
> +
> +.. code-block:: C
> +
> +   static bool my_flag;
> +
> +   static struct rte_argparse obj = {
> +      .args = {
> +         { "--enable", "-e", "Enable feature", &my_flag, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_BOOL },
> +         ARGPARSE_ARG_END(),
> +      },
> +   };
> +
>  Parsing by callback way
>  ~~~~~~~~~~~~~~~~~~~~~~~
>  
> @@ -167,8 +236,8 @@ It could also choose to use callback to parse,
>  just define a unique index for the argument
>  and make the ``val_save`` field to be NULL also zero value-type.
>  
> -In the above example, the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp``
> -both use this way.
> +In the example at the top of this section,
> +the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp`` all use this way.
>  
>  Multiple times argument
>  ~~~~~~~~~~~~~~~~~~~~~~~



More information about the dev mailing list