ArgSpec
Description
Internal registration record. One entry per ArgRequired / ArgOptional / ArgFlag / ArgCount / ArgPositional call. Lives in the ArgParse.specs Vec; populated at registration time, mutated during ArgParseRun.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
ArgParse.h:122:
void *target;
bool seen; // set during parse so missing-required can be checked
} ArgSpec;
typedef Vec(ArgSpec) ArgSpecs;- In
ArgParse.h:124:
} ArgSpec;
typedef Vec(ArgSpec) ArgSpecs;
///
- In
ArgParse.c:238:
// ---------------------------------------------------------------------------
static ArgSpec *find_long(ArgParse *self, Zstr long_name) {
VecForeachPtr(&self->specs, sp) {
if (sp->role == ARG_ROLE_POSITIONAL)- In
ArgParse.c:248:
}
static ArgSpec *find_short(ArgParse *self, Zstr short_name) {
VecForeachPtr(&self->specs, sp) {
if (sp->role == ARG_ROLE_POSITIONAL)- In
ArgParse.c:266:
// long-flag name upper-cased and hyphens swapped for underscores. For
// short-only options without a long form we fall back to "VALUE".
static void append_metavar(Str *out, const ArgSpec *sp) {
Zstr src = sp->long_name;
if (!src) {- In
ArgParse.c:287:
// Build the " -l, --listen <LISTEN>" left column for one spec. Returns
// the visible width so the caller can pad to a shared right margin.
static u64 spec_format_left(const ArgSpec *sp, Str *out) {
u64 start = StrLen(out);
StrPushBackMany(out, " ");- In
ArgParse.c:384:
bool printed_options_header = false;
for (u64 i = 0; i < n_specs; ++i) {
ArgSpec *sp = VecPtrAt(&self->specs, i);
if (sp->role != ARG_ROLE_POSITIONAL)
continue;- In
ArgParse.c:400:
for (u64 i = 0; i < n_specs; ++i) {
ArgSpec *sp = VecPtrAt(&self->specs, i);
if (sp->role == ARG_ROLE_POSITIONAL)
continue;- In
ArgParse.c:445:
}
ArgSpec sp = {0};
sp.short_name = short_name;
sp.long_name = long_name;- In
ArgParse.c:507:
}
ArgSpec *sp = is_long ? find_long(self, flag) : find_short(self, flag);
if (!sp) {
FWriteFmtLn(err, "{}: unknown option: {}", self->name, flag);- In
ArgParse.c:593:
StrResize(&buf, 2);
ArgSpec *sp = find_short(self, (Zstr)data);
if (!sp) {
FWriteFmtLn(err, "{}: unknown option: {}", self->name, (Zstr)data);- In
ArgParse.c:636:
if (!already_has_help) {
// Help has no target; we short-circuit before any store_value.
ArgSpec help = {0};
help.short_name = "-h";
help.long_name = "--help";- In
ArgParse.c:690:
StrResize(&two, 2);
ArgSpec *first = find_short(self, (Zstr)data);
if (first && (first->role == ARG_ROLE_FLAG || first->role == ARG_ROLE_COUNT)) {
decision = BUNDLE_TRY;- In
ArgParse.c:726:
// Find the n-th positional spec.
u64 seen = 0;
ArgSpec *pos = NULL;
VecForeachPtr(&self->specs, sp) {
if (sp->role != ARG_ROLE_POSITIONAL)
Last updated on