ArgParseInit
Description
Create a parser. The name and about pointers are borrowed – they must outlive the parser (string literals are the typical case). The -h / --help flag is registered lazily on the first ArgParseRun / ArgParseHelp call.
Two call shapes, like StrInit / VecInitT: ArgParseInit(name, about) – uses the surrounding Scope’s allocator. ArgParseInit(name, about, alloc) – explicit allocator.
Success
Yields an initialized parser. The specs Vec is empty; add specs with ArgParseAddPositional / etc.
Failure
Cannot fail at construction; first allocator OOM surfaces from later spec-Vec growth.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Resolve.c:23:
Zstr hostname = NULL;
ArgParse ap = ArgParseInit("resolve", "look up a hostname via /etc/hosts and DNS");
ArgPositional(&ap, "hostname", &hostname, "name to resolve");- In
Beam.c:391:
Zstr upstream_spec = NULL;
ArgParse ap = ArgParseInit("beam", "small reverse-proxy");
ArgRequired(&ap, "-l", "--listen", &listen_spec, "host:port to listen on");
ArgRequired(&ap, "-u", "--upstream", &upstream_spec, "upstream host:port");- In
ArgParse.c:24:
static bool test_required_long_space(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
Zstr listen = NULL;- In
ArgParse.c:40:
static bool test_required_long_equals(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
Zstr listen = NULL;- In
ArgParse.c:56:
static bool test_required_short(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
Zstr listen = NULL;- In
ArgParse.c:72:
static bool test_optional_default_preserved(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
u32 timeout = 30;- In
ArgParse.c:88:
static bool test_optional_overrides_default(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
u32 timeout = 30;- In
ArgParse.c:104:
static bool test_flag_presence(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
bool verbose = false;- In
ArgParse.c:120:
static bool test_flag_absence(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
bool verbose = false;- In
ArgParse.c:136:
static bool test_count_repeated(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
u32 verbose = 0;- In
ArgParse.c:152:
static bool test_count_bundled(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
u32 verbose = 0;- In
ArgParse.c:168:
static bool test_positional_order(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("cp", NULL, &a);
Zstr src = NULL;- In
ArgParse.c:186:
static bool test_positional_with_interleaved_flag(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("cp", NULL, &a);
Zstr src = NULL;- In
ArgParse.c:210:
static bool test_type_inferred_u32(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
u32 n = 0;- In
ArgParse.c:226:
static bool test_type_inferred_i64_negative(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
i64 v = 0;- In
ArgParse.c:242:
static bool test_type_inferred_f64(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
f64 ratio = 1.0;- In
ArgParse.c:258:
static bool test_type_inferred_str(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
Str name = StrInit(&a);- In
ArgParse.c:279:
static bool test_missing_required(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
Zstr listen = NULL;- In
ArgParse.c:295:
static bool test_missing_positional(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("cp", NULL, &a);
Zstr src = NULL;- In
ArgParse.c:313:
static bool test_unknown_option(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
bool v = false;- In
ArgParse.c:329:
static bool test_invalid_value_for_type(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
u32 n = 0;- In
ArgParse.c:345:
static bool test_u8_overflow(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
u8 v = 0;- In
ArgParse.c:361:
static bool test_too_many_positionals(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", NULL, &a);
Zstr x = NULL;- In
ArgParse.c:381:
static bool test_double_dash_separator(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("cat", NULL, &a);
Zstr file = NULL;- In
ArgParse.c:405:
static bool test_help_returns_help_code(void) {
DefaultAllocator a = DefaultAllocatorInit();
ArgParse p = ArgParseInit("prog", "test prog", &a);
Zstr required = NULL;
Last updated on