rte_argparse.h(3)

πŸ’– rte_argparse.h πŸ’–

okay so bestie, this is a page straight out of the Library Functions Manual β€” it's the manual for rte_argparse.h, and it's genuinely one of the cutest little APIs for letting your program eat command-line arguments without you writing a million if statements. sit down, grab a strawberry πŸ“, we're doing this.


✨ NAME ✨

rte_argparse.h β€” the argument parsing API, periodt.


🌈 SYNOPSIS 🌈

#include <stdbool.h>
#include <stdint.h>
#include <rte_bitops.h>
#include <rte_compat.h>

πŸŽ€ Data Structures

  • struct rte_argparse_arg
  • struct rte_argparse

πŸŽ€ Macros

#define RTE_ARGPARSE_HAS_VAL_BITMASK   RTE_GENMASK64(1, 0)
#define RTE_ARGPARSE_VAL_TYPE_BITMASK   RTE_GENMASK64(9, 2)

Flag definition (in bitmask form) for an argument

Note β€” Bits[0~1] represent the argument whether has value, bits[2~9] represent the value type which used when autosave.

See also β€” struct rte_argparse_arg::flags

#define RTE_ARGPARSE_ARG_NO_VALUE   RTE_SHIFT_VAL64(1, 0)
#define RTE_ARGPARSE_ARG_REQUIRED_VALUE   RTE_SHIFT_VAL64(2, 0)
#define RTE_ARGPARSE_ARG_OPTIONAL_VALUE   RTE_SHIFT_VAL64(3, 0)
#define RTE_ARGPARSE_ARG_VALUE_INT   RTE_SHIFT_VAL64(1, 2)
#define RTE_ARGPARSE_ARG_VALUE_U8   RTE_SHIFT_VAL64(2, 2)
#define RTE_ARGPARSE_ARG_VALUE_U16   RTE_SHIFT_VAL64(3, 2)
#define RTE_ARGPARSE_ARG_VALUE_U32   RTE_SHIFT_VAL64(4, 2)
#define RTE_ARGPARSE_ARG_VALUE_U64   RTE_SHIFT_VAL64(5, 2)
#define RTE_ARGPARSE_ARG_VALUE_MAX   RTE_SHIFT_VAL64(6, 2)
#define RTE_ARGPARSE_ARG_SUPPORT_MULTI   RTE_BIT64(10)
#define RTE_ARGPARSE_ARG_RESERVED_FIELD   RTE_GENMASK64(63, 48)

πŸŽ€ Typedefs

typedef int(* rte_arg_parser_t) (uint32_t index, const char *value, void *opaque)

πŸŽ€ Functions

  • __rte_experimental int rte_argparse_parse (struct rte_argparse *obj, int argc, char **argv)
  • __rte_experimental int rte_argparse_parse_type (const char *str, uint64_t val_type, void *val)

πŸ¦‹ Detailed Description πŸ¦‹

Argument parsing API. πŸ’…

The argument parsing API makes it easy to write user-friendly command-line program. The program defines what arguments it requires, and the API will parse those arguments from [argc, argv].

The API provides the following functions:

  1. Support parsing optional argument (which could take with no-value, required-value and optional-value.
  2. Support parsing positional argument (which must take with required-value).
  3. Support automatic generate usage information.
  4. Support issue errors when provided with invalid arguments.

There are two ways to parse arguments:

  1. AutoSave: for which known value types, the way can be used.
  2. Callback: will invoke user callback to parse.

Definition in file rte_argparse.h.


🌸 Macro Definition Documentation 🌸

#define RTE_ARGPARSE_ARG_NO_VALUE RTE_SHIFT_VAL64(1, 0)

The argument has no value. literally just vibes, no payload attached. πŸ™ˆ

Definition at line 48 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_REQUIRED_VALUE RTE_SHIFT_VAL64(2, 0)

The argument must have a value. no value, no entry bestie, it's mandatory. πŸ‘‘

Definition at line 50 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_OPTIONAL_VALUE RTE_SHIFT_VAL64(3, 0)

The argument has optional value. it can show up with a plus-one or solo, both iconic.

Definition at line 52 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_VALUE_INT RTE_SHIFT_VAL64(1, 2)

The argument's value is int type.

Definition at line 54 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_VALUE_U8 RTE_SHIFT_VAL64(2, 2)

The argument's value is uint8 type.

Definition at line 56 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_VALUE_U16 RTE_SHIFT_VAL64(3, 2)

The argument's value is uint16 type.

Definition at line 58 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_VALUE_U32 RTE_SHIFT_VAL64(4, 2)

The argument's value is uint32 type.

Definition at line 60 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_VALUE_U64 RTE_SHIFT_VAL64(5, 2)

The argument's value is uint64 type.

Definition at line 62 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_VALUE_MAX RTE_SHIFT_VAL64(6, 2)

Max value type.

Definition at line 64 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_SUPPORT_MULTI RTE_BIT64(10)

Flag for that argument support occur multiple times. This flag can be set only when the argument is optional. When this flag is set, the callback type must be used for parsing. so like β€” you can pass it over and over, but only if it's optional, and only if you're riding the callback path. no cap. πŸ”₯

Definition at line 70 of file rte_argparse.h.

#define RTE_ARGPARSE_ARG_RESERVED_FIELD RTE_GENMASK64(63, 48)

Reserved for this library implementation usage. hands off, that's the library's business. πŸ™…

Definition at line 72 of file rte_argparse.h.

#define RTE_ARGPARSE_HAS_VAL_BITMASK RTE_GENMASK64(1, 0)

Bitmask used to get the argument whether has value.

Definition at line 76 of file rte_argparse.h.

#define RTE_ARGPARSE_VAL_TYPE_BITMASK RTE_GENMASK64(9, 2)

Bitmask used to get the argument's value type.

Definition at line 78 of file rte_argparse.h.


🧚 Typedef Documentation 🧚

typedef int(* rte_arg_parser_t) (uint32_t index, const char *value, void *opaque)

Callback prototype used by parsing specified arguments. this is the function you hand over so the parser knows who to call. 🫢

Parameters

  • index β€” The argument's index, coming from argument's val_set field.
  • value β€” The value corresponding to the argument, it may be NULL (e.g. the argument has no value, or the argument has optional value but doesn't provided value).
  • opaque β€” An opaque pointer coming from the caller.

Returns β€” 0 on success. Otherwise negative value is returned.

Definition at line 140 of file rte_argparse.h.


⭐ Function Documentation ⭐

__rte_experimental int rte_argparse_parse (struct rte_argparse * obj, int argc, char ** argv)

Warning β€” EXPERIMENTAL: this API may change without prior notice. ⚠️ like, she's still in her experimental era, don't build your whole life on her just yet.

Parse parameters.

Parameters

  • obj β€” Parser object.
  • argc β€” Parameters count.
  • argv β€” Array of parameters points.

Returns β€” 0 on success. Otherwise negative value is returned.

__rte_experimental int rte_argparse_parse_type (const char * str, uint64_t val_type, void * val)

Warning β€” EXPERIMENTAL: this API may change without prior notice. ⚠️ same deal, experimental arc, proceed with awareness.

Parse the value from the input string based on the value type.

Parameters

  • str β€” Input string.
  • val_type β€” The value type,

See also β€” RTE_ARGPARSE_ARG_VALUE_INT or other type.

Parameters

  • val β€” Saver for the value.

Returns β€” 0 on success. Otherwise negative value is returned.


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for DPDK from the source code.


and that's the whole page, bestie β€” slay ✨ this manual came out of DPDK, Version 24.11.8, and honestly? it ate. go write your CLI like the main character you are. πŸ’œπŸŽ€πŸ¦‹

πŸ“¦ where this page comes from