clix
Single-header file CLI libraries for C
Loading...
Searching...
No Matches
Decentralized CLI Argument Framework

Overview

args.h provides a header-only argument manager intended for modular C codebases. Arguments are declared with ARGUMENT in any source file, registered automatically, then processed in three explicit stages: parsing, validation, and actions.

Feature Highlights

  • Distributed argument declarations with constructor-based registration.
  • Automatic help generation.
  • Dependency/conflict/subset relationships between arguments.
  • Automatic validation of required arguments and relation rules.
  • Typed parsing helpers via ARG_PARSER family.
  • Validation and general callbacks with flexible execution policies.
  • Deterministic cross-file ordering for help, validate, and action stages.

Quick Start

#define ARGS_IMPLEMENTATION
#include "args.h"
// Simple flag argument example
static bool my_flag;
static void print_my_flag(void)
{
printf("Hello from my_flag\n");
}
ARGUMENT(my_flag) = {
.set = &my_flag,
.action_callback = print_my_flag,
.action_phase = ARG_CALLBACK_IF_SET,
.help = "Enable my flag",
.lopt = "my-flag",
.opt = 'f',
};
int main(int argc, char **argv) {
if (!args_parse(argc, argv) || !args_validate())
return 1;
printf("My flag is %s\n", my_flag ? "enabled!" : "disabled!");
return 0;
}
// Possible outputs:
//
// $ ./my_program
// My flag is disabled!
//
// $ ./my_program -f
// Hello from my_flag!
// My flag is enabled!
//
// $ ./my_program -h
// Usage: ./my_program [ARGUMENTS]
//
// Optional arguments:
// -f, --my-flag Enable my flag
// -h, --help Display this help message
@ ARG_CALLBACK_IF_SET
Definition args.h:438
#define ARGUMENT(name)
Creates and registers a new argument object.
Definition args.h:146
bool args_validate(void)
Validates argument schema rules and user-provided combinations.
void args_actions(void)
Executes action callbacks for arguments matching action phase rules.
bool args_parse(int argc, char *argv[])
Parses command line arguments and runs parse-phase relations.

Docs Navigation