Declarative schema object for one CLI argument.
Initialize this type through ARGUMENT. C designated initializers let you specify only the fields you need.
Data Fields | |
Storage | |
| bool * | set |
| Tracks whether the user supplied this argument. | |
| void * | dest |
Destination pointer passed as dest to parser callbacks. | |
Callbacks | |
| struct arg_callback(* | parse_callback )(const char *str, void *dest) |
| Function invoked during args_parse. | |
| struct arg_callback(* | validate_callback )(void) |
| Function invoked during args_validate. | |
| void(* | action_callback )(void) |
| Function invoked during args_actions. | |
Schema | |
| enum arg_requirement | arg_req |
| Specifies whether this argument is required, optional, or hidden. | |
| enum arg_parameter | param_req |
| Specifies whether this argument takes a parameter and if it's required. | |
| enum arg_callback_phase | validate_phase |
| Controls when argument::validate_callback runs. | |
| enum arg_callback_phase | action_phase |
| Controls when argument::action_callback runs. | |
Ordering | |
| struct argument * | validate_order |
| Ordering for validation. | |
| struct argument * | action_order |
| Ordering for action execution. | |
| struct argument * | help_order |
| Ordering for help display. | |
Help Presentation | |
| const char * | help |
| Help description for this argument. | |
| const char * | param |
| Parameter name for help display (e.g., "N" for a number). | |
| const char * | lopt |
Long option name (e.g. "output" -> --output). | |
| char | opt |
Short option character (e.g. 'o' -> -o). | |
| bool* argument::set |
Tracks whether the user supplied this argument.
If NULL, it is allocated implicitly when needed by schema features.
| struct arg_callback(* argument::parse_callback) (const char *str, void *dest) |
Function invoked during args_parse.
Use ARG_PARSER helpers for numeric parsing, or provide custom logic. Callbacks aren't limited to parsing e.g. –help exiting immediately.
str is NULL when argument::param_req is arg_parameter::ARG_PARAM_NONE. dest ( argument::dest ) is NULL if you didn't initialize it.Example:
You can also write custom parsers:
| str | User-provided value string. |
| dest | Alias of argument::dest, potentially NULL. |
| ARG_VALID | Callback accepted input. |
| ARG_INVALID | Callback rejected input. |
| struct arg_callback(* argument::validate_callback) (void) |
Function invoked during args_validate.
Use for project-specific constraints after the parse stage.
Example:
| ARG_VALID | Validation succeeded. |
| ARG_INVALID | Validation failed. |
| void(* argument::action_callback) (void) |
Function invoked during args_actions.
Intended for side effects such as applying runtime configuration.
Example:
| enum arg_requirement argument::arg_req |
Specifies whether this argument is required, optional, or hidden.
| enum arg_parameter argument::param_req |
Specifies whether this argument takes a parameter and if it's required.
| enum arg_callback_phase argument::validate_phase |
Controls when argument::validate_callback runs.
| enum arg_callback_phase argument::action_phase |
Controls when argument::action_callback runs.
| struct argument* argument::validate_order |
Ordering for validation.
Use ARG_ORDER_FIRST or ARG_ORDER_AFTER, NULL means append at the end.
| struct argument* argument::action_order |
Ordering for action execution.
Use ARG_ORDER_FIRST or ARG_ORDER_AFTER, NULL means append at the end.
| struct argument* argument::help_order |
Ordering for help display.
Use ARG_ORDER_FIRST or ARG_ORDER_AFTER, NULL means append at the end.
| const char* argument::help |
Help description for this argument.
Multiline strings are supported (e.g. "Line1\nLine2").
| const char* argument::param |
Parameter name for help display (e.g., "N" for a number).