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.c:232:
/* ------------------------------------------------------------------ */
static ArgSpec *find_long(ArgParse *self, const char *long_name) {
VecForeachPtr(&self->specs, sp) {
if (sp->role == ARG_ROLE_POSITIONAL)- In
ArgParse.c:242:
}
static ArgSpec *find_short(ArgParse *self, const char *short_name) {
VecForeachPtr(&self->specs, sp) {
if (sp->role == ARG_ROLE_POSITIONAL)- In
ArgParse.c:260:
// 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) {
const char *src = sp->long_name;
if (!src) {- In
ArgParse.c:281:
// 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 = out->length;
StrPushBackZstr(out, " ");- In
ArgParse.c:378:
bool printed_options_header = false;
for (u64 i = 0; i < n_specs; ++i) {
ArgSpec *sp = &self->specs.data[i];
if (sp->role != ARG_ROLE_POSITIONAL)
continue;- In
ArgParse.c:394:
for (u64 i = 0; i < n_specs; ++i) {
ArgSpec *sp = &self->specs.data[i];
if (sp->role == ARG_ROLE_POSITIONAL)
continue;- In
ArgParse.c:446:
}
ArgSpec sp = {0};
sp.short_name = short_name;
sp.long_name = long_name;- In
ArgParse.c:515:
}
ArgSpec *sp = is_long ? find_long(self, flag) : find_short(self, flag);
if (!sp) {
FWriteFmtLn(err, "{}: unknown option: {}", self->name, flag);- In
ArgParse.c:587:
for (const char *p = tok + 1; *p; ++p) {
char buf[3] = {'-', *p, 0};
ArgSpec *sp = find_short(self, (const char *)buf);
if (!sp) {
FWriteFmtLn(err, "{}: unknown option: {}", self->name, (const char *)buf);- In
ArgParse.c:624:
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:668:
if (tok[2] != '\0') {
char two[3] = {'-', tok[1], 0};
ArgSpec *first = find_short(self, (const char *)two);
if (first && (first->role == ARG_ROLE_FLAG || first->role == ARG_ROLE_COUNT)) {
ArgRun r = handle_short_bundle(self, tok, &err);- In
ArgParse.c:699:
// Find the n-th positional spec.
u64 seen = 0;
ArgSpec *pos = NULL;
VecForeachPtr(&self->specs, sp) {
if (sp->role != ARG_ROLE_POSITIONAL)- In
ArgParse.h:120:
void *target;
bool seen; // set during parse so missing-required can be checked
} ArgSpec;
typedef Vec(ArgSpec) ArgSpecs;- In
ArgParse.h:122:
} ArgSpec;
typedef Vec(ArgSpec) ArgSpecs;
///
Last updated on