ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
registry.h File Reference

Central registry of all command-line options with mode applicability. More...

Go to the source code of this file.

Typedefs

typedef struct flags_schema_builder flags_schema_builder_t

Functions

asciichat_error_t options_registry_add_all_to_builder (options_builder_t *builder)
 Add all options from registry to builder.
asciichat_error_t registry_add_all_to_flags_builder (flags_schema_builder_t *builder, option_mode_bitmask_t mode_mask)
const option_descriptor_t * options_registry_find_by_name (const char *long_name)
 Get option descriptor by name.
const option_descriptor_t * options_registry_find_by_short (char short_name)
 Get option descriptor by short name.
const option_descriptor_t * options_registry_get_for_mode (asciichat_mode_t mode, size_t *num_options)
 Get all options for a specific mode.
const option_descriptor_t * options_registry_get_binary_options (size_t *num_options)
 Get all binary-level options.
const option_descriptor_t * options_registry_get_for_display (asciichat_mode_t mode, bool for_binary_help, size_t *num_options)
 Get options for help/completions display with unified filtering.
const option_metadata_t * options_registry_get_metadata (const char *long_name)
 Get complete metadata for an option.
const registry_entry_t * registry_get_raw (void)
 Get raw access to registry for completions filtering.
const char ** options_registry_get_enum_values (const char *option_name, const char ***descriptions, size_t *count)
 Get enum values for an option.
bool options_registry_get_numeric_range (const char *option_name, int *min_out, int *max_out, int *step_out)
 Get numeric range for an option.
const char ** options_registry_get_examples (const char *option_name, size_t *count)
 Get example values for an option.
option_input_type_t options_registry_get_input_type (const char *option_name)
 Get input type for an option.

Detailed Description

Central registry of all command-line options with mode applicability.

This module defines the single source of truth for all command-line options that can be used across all modes (server, client, mirror, discovery service, etc.).

Architecture Overview

The registry is the single source of truth for option definitions. It works with:

  • Builder (builder.h): Use builder to construct custom option configurations, populated from the registry via options_registry_add_all_to_builder().
  • RCU Thread-Safety (rcu.h): Registered options are parsed and published to RCU for lock-free thread-safe access via GET_OPTION() macro.
  • Options System (options.h): The unified parsing system uses the registry to build option configurations for different modes.

Design Philosophy

  • Single Definition: Each option defined exactly once with all metadata (no duplication)
  • Mode Bitmasks: Each option includes mode_bitmask indicating which modes it applies to
  • Automatic Filtering: Registry functions automatically filter by mode
  • Immutable After Load: Once loaded, registry is read-only (no runtime modifications)
  • Shared with Builder: Registry options added to builder via options_registry_add_all_to_builder()
  • Completion Metadata: Each option includes shell completion hints (enums, ranges, examples)

Registry Structure

The registry is defined in registry.c as a static array of option_descriptor_t structures. Each descriptor includes complete metadata:

Identification:

  • Long name (e.g., "port")
  • Short name (e.g., 'p')
  • Argument placeholder (e.g., "NUM", "STR", "PATH")

Type and Storage:

  • Type: BOOL, INT, STRING, DOUBLE, CALLBACK, ACTION
  • Offset into options_t struct (via offsetof())

Documentation:

  • Help text (brief description for –help output)
  • Group name (for organizing help sections: "NETWORK OPTIONS", "DISPLAY OPTIONS", etc.)
  • Visibility flags (hide_from_binary_help, hide_from_mode_help)

Values and Validation:

  • Default value pointer
  • Required flag (must user provide this option?)
  • Environment variable fallback (e.g., PORT, PASSWORD_FILE)
  • Custom validator function (validates across option fields)

Parsing and Actions:

  • Custom parser for OPTION_TYPE_CALLBACK
  • Action function for OPTION_TYPE_ACTION (executes immediately, may exit)

Mode Applicability:

  • Bitmask indicating which modes this option applies to

Completion Metadata (Phase 3):

  • Enum values and descriptions (for shell completions)
  • Numeric range (min, max, step)
  • Example values
  • Input type hint (ENUM, NUMERIC, FILEPATH, CHOICE, etc.)

Mode Bitmask System

Each option includes a mode_bitmask that controls where it appears:

Mode Bitmask Values:

Examples:

.mode_bitmask = OPTION_MODE_CLIENT | OPTION_MODE_MIRROR // Client and mirror modes
.mode_bitmask = OPTION_MODE_SERVER // Server mode only
.mode_bitmask = OPTION_MODE_BINARY | OPTION_MODE_CLIENT // Binary + client options
.mode_bitmask = OPTION_MODE_ALL // All modes
@ OPTION_MODE_ALL
All modes + binary.
Definition options.h:943
@ OPTION_MODE_BINARY
Binary-level options (parsed before mode detection).
Definition options.h:942
@ OPTION_MODE_CLIENT
Client mode (bit 1).
Definition options.h:936
@ OPTION_MODE_SERVER
Server mode (bit 0).
Definition options.h:935
@ OPTION_MODE_MIRROR
Mirror mode (bit 2).
Definition options.h:937

How Mode Filtering Works:

  1. User runs ascii-chat client or ascii-chat server
  2. Mode detection determines detected_mode (MODE_CLIENT, MODE_SERVER, etc.)
  3. Registry functions filter options by matching mode_bitmask
  4. Parser only accepts options for the detected mode
  5. Help output only shows relevant options

Usage Patterns

Pattern 1: Get all options for a specific mode

size_t num_opts;
for (size_t i = 0; i < num_opts; i++) {
printf(\"%s: %s\\n\", opts[i].long_name, opts[i].help_text);
}
@ MODE_CLIENT
Client mode - network client options.
Definition options.h:918
const option_descriptor_t * options_registry_get_for_mode(asciichat_mode_t mode, size_t *num_options)
Get all options for a specific mode.
Definition public_api.c:181
The complete registry entry for one command-line/configuration option.
Definition builder.h:251

Pattern 2: Look up individual options

if (port_opt && (port_opt->mode_bitmask & OPTION_MODE_SERVER)) {
printf(\"Port option available in server mode\\n\");
}
const option_descriptor_t * options_registry_find_by_name(const char *long_name)
Get option descriptor by name.

Pattern 3: Populate builder with registry options

options_registry_add_all_to_builder(builder); // Add all registered options
options_config_t * options_builder_build(options_builder_t *builder)
Build immutable options config.
options_builder_t * options_builder_create(size_t struct_size)
Mutable owner used to assemble option descriptors, dependencies, help sections, and examples before b...
struct options_state options_t
Immutable, RCU-published snapshot of the application's runtime configuration.
asciichat_error_t options_registry_add_all_to_builder(options_builder_t *builder)
Add all options from registry to builder.
Definition public_api.c:168
Immutable parsing tables produced from an options builder.
Definition builder.h:459
Immutable parsing tables produced from an options builder.
Definition builder.h:415

Pattern 4: Get shell completion metadata

const option_metadata_t *meta = options_registry_get_metadata(\"color-mode\");
if (meta && meta->input_type == OPTION_INPUT_ENUM) {
size_t count;
const char **values = options_registry_get_enum_values(\"color-mode\", NULL, &count);
// Use values for shell completion suggestions
}
const option_metadata_t * options_registry_get_metadata(const char *long_name)
Get complete metadata for an option.
Definition public_api.c:251
Completion metadata attached to one option descriptor.
Definition builder.h:201

Adding New Options to Registry

To add a new option to the registry:

  1. Add field to options_t struct in include/ascii-chat/options/options.h
  2. Add default constant in options.h (e.g., OPT_MY_OPTION_DEFAULT)
  3. Add registry entry in lib/options/registry/ with:
    • Long and short names
    • Type and storage offset (via offsetof)
    • Default value and validation function
    • Help text and group name
    • Mode bitmask(s) indicating which modes apply
    • Completion metadata (if enum, ranges, or examples needed)

Example Registry Entry:

{
.long_name = \"max-clients\",
.short_name = 'c',
.type = OPTION_TYPE_INT,
.offset = offsetof(options_t, max_clients),
.default_value = &(int){OPT_MAX_CLIENTS_DEFAULT},
.help_text = \"Maximum number of simultaneous clients\",
.group = \"NETWORK OPTIONS\",
.mode_bitmask = OPTION_MODE_SERVER,
.validate = validate_max_clients, // Custom validator
.metadata = {
.input_type = OPTION_INPUT_NUMERIC,
.numeric_range = {.min = 1, .max = 100, .step = 1},
.examples = (const char *[]){\"1\", \"4\", \"10\", NULL},
}
}

Registry Lookup Functions

Core Functions:

Completion Metadata Functions (Phase 3):

RCU Thread-Safety Integration

After registry options are parsed through the builder, they're published via RCU:

// Build config from registered options
// Parse command line
options_config_parse(config, argc, argv, &opts, MODE_DETECTION_RESULT, ...);
// Publish to RCU (lock-free access from worker threads)
// Worker threads now read lock-free via GET_OPTION() macro
asciichat_error_t options_config_parse(const options_config_t *config, int argc, char **argv, void *options_struct, option_mode_bitmask_t detected_mode, int *remaining_argc, char ***remaining_argv)
Parse command-line arguments.
options_t options_t_new(void)
Initialize options by parsing command-line arguments.
Definition options.c:643
asciichat_error_t options_state_init(void)
Initialize RCU options system.
Definition rcu.c:374
asciichat_error_t options_state_set(const options_t *opts)
Set options from a parsed options struct.
Definition rcu.c:443
See also
builder.h - Builder API for constructing option configurations
rcu.h - Thread-safe RCU-based access to published Options Module
options.h - Unified Options Module parsing system (uses registry internally)
Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
January 2026

Definition in file lib/options/registry/registry.h.

Typedef Documentation

◆ flags_schema_builder_t

typedef struct flags_schema_builder flags_schema_builder_t

Definition at line 216 of file lib/options/registry/registry.h.

Function Documentation

◆ options_registry_add_all_to_builder()

asciichat_error_t options_registry_add_all_to_builder ( options_builder_t * builder)

Add all options from registry to builder.

Iterates through the central options registry and adds each option to the provided builder with its mode bitmask set.

Parameters
builderOptions builder to add options to
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 168 of file public_api.c.

168 {
169 if (!builder)
170 return SET_ERRNO(ERROR_INVALID_PARAM, "Builder is NULL");
172 for (size_t i = 0; i < g_registry_size; ++i) {
173 if (g_options_registry[i].long_name) {
175 options_builder_add_descriptor(builder, &descriptor);
176 }
177 }
178 return ASCIICHAT_OK;
179}
#define SET_ERRNO(code,...)
void options_builder_add_descriptor(options_builder_t *builder, const option_descriptor_t *descriptor)
Add full option descriptor (advanced).
option_descriptor_t registry_entry_to_descriptor(const registry_entry_t *entry)
Definition core.c:157
void registry_init_size(void)
Initialize registry size and metadata.
Definition core.c:107
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
registry_entry_t g_options_registry[2048]
Definition registry.c:41
size_t g_registry_size
Definition registry.c:43

◆ options_registry_find_by_name()

const option_descriptor_t * options_registry_find_by_name ( const char * long_name)

Get option descriptor by name.

Looks up an option descriptor from the registry by its long name.

Parameters
long_nameLong option name (e.g., "port")
Returns
Pointer to option descriptor, or NULL if not found

◆ options_registry_find_by_short()

const option_descriptor_t * options_registry_find_by_short ( char short_name)

Get option descriptor by short name.

Looks up an option descriptor from the registry by its short name.

Parameters
short_nameShort option character (e.g., 'p')
Returns
Pointer to option descriptor, or NULL if not found

◆ options_registry_get_binary_options()

const option_descriptor_t * options_registry_get_binary_options ( size_t * num_options)

Get all binary-level options.

Returns an array of all binary-level options (those with OPTION_MODE_BINARY). The array is allocated and must be freed by the caller.

Parameters
num_optionsOUTPUT: Number of options returned
Returns
Array of option descriptors (caller must free), or NULL on error

◆ options_registry_get_enum_values()

const char ** options_registry_get_enum_values ( const char * option_name,
const char *** descriptions,
size_t * count )

Get enum values for an option.

Retrieves enum values and descriptions for an option that has OPTION_INPUT_ENUM type in its metadata.

Parameters
option_nameLong name of option
descriptionsOUTPUT: Pointer to descriptions array (or NULL if not needed)
countOUTPUT: Number of values/descriptions
Returns
Array of enum value strings, or NULL if not found or not an enum type

Example:

const char **values;
const char **descs;
size_t count;
values = options_registry_get_enum_values("color-mode", &descs, &count);
if (values) {
for (size_t i = 0; i < count; i++) {
printf("%s: %s\n", values[i], descs[i]);
}
}
const char ** options_registry_get_enum_values(const char *option_name, const char ***descriptions, size_t *count)
Get enum values for an option.
Definition public_api.c:272

Definition at line 272 of file public_api.c.

272 {
273 if (!option_name || !count) {
274 SET_ERRNO(ERROR_INVALID_PARAM, "Option name is NULL or count is NULL");
275 if (count)
276 *count = 0;
277 return NULL;
278 }
279
280 const option_metadata_t *meta = options_registry_get_metadata(option_name);
281 if (!meta || meta->input_type != OPTION_INPUT_ENUM || !meta->enum_values || meta->enum_values[0] == NULL) {
282 SET_ERRNO(ERROR_NOT_FOUND, "Option '%s' not found", option_name);
283 *count = 0;
284 if (descriptions)
285 *descriptions = NULL;
286 return NULL;
287 }
288
289 // Count enum values (NULL-terminated array)
290 size_t enum_count = 0;
291 while (meta->enum_values[enum_count] != NULL) {
292 enum_count++;
293 }
294
295 *count = enum_count;
296 if (descriptions) {
297 *descriptions = meta->enum_descriptions;
298 }
299 return meta->enum_values;
300}
@ OPTION_INPUT_ENUM
Choose from fixed set of enum values.
Definition builder.h:187
@ ERROR_NOT_FOUND
const char ** enum_values
Enum value strings (null-terminated, e.g., {"auto", "none", "16", "256", "truecolor",...
Definition builder.h:203
option_input_type_t input_type
What kind of input this option expects.
Definition builder.h:221
const char ** enum_descriptions
Descriptions parallel to enum_values (null-terminated, e.g., "Auto-detect from terminal").
Definition builder.h:204

◆ options_registry_get_examples()

const char ** options_registry_get_examples ( const char * option_name,
size_t * count )

Get example values for an option.

Retrieves example values or command invocations for an option.

Parameters
option_nameLong name of option
countOUTPUT: Number of examples
Returns
Array of example strings, or NULL if no examples defined

Definition at line 322 of file public_api.c.

322 {
323 if (!option_name || !count) {
324 SET_ERRNO(ERROR_INVALID_PARAM, "Option name is NULL or count is NULL");
325 if (count)
326 *count = 0;
327 return NULL;
328 }
329
330 const option_metadata_t *meta = options_registry_get_metadata(option_name);
331 if (!meta || !meta->examples || meta->examples[0] == NULL) {
332 *count = 0;
333 return NULL;
334 }
335
336 // Count examples by finding NULL terminator
337 size_t example_count = 0;
338 for (size_t i = 0; meta->examples[i] != NULL; i++) {
339 example_count++;
340 }
341
342 *count = example_count;
343 return meta->examples;
344}
const char ** examples
Example values or command invocations (null-terminated array).
Definition builder.h:215

◆ options_registry_get_for_display()

const option_descriptor_t * options_registry_get_for_display ( asciichat_mode_t mode,
bool for_binary_help,
size_t * num_options )

Get options for help/completions display with unified filtering.

Returns options filtered using the same logic as the help system. This ensures help output and completions are always in sync.

Uses the same filtering rules as options_print_help_for_mode():

  • For binary-level help (mode == MODE_DISCOVERY): shows all options that apply to any mode
  • For mode-specific help: shows only options for that mode (binary options excluded unless also mode-specific)
  • Respects hide_from_binary_help and hide_from_mode_help flags
Parameters
modeMode to filter for (use MODE_DISCOVERY for binary-level help)
for_binary_helpIf true, use binary-help filtering; if false, use mode-specific filtering
num_optionsOUTPUT: Number of options returned
Returns
Array of option descriptors (caller must free), or NULL on error
Note
This is the AUTHORITATIVE filtering function for both help and completions. Always use this function to ensure consistency across the application.

Definition at line 204 of file public_api.c.

204 {
205 if (!num_options)
206 return NULL;
208 size_t count = 0;
209 for (size_t i = 0; i < g_registry_size; ++i)
210 count += registry_entry_applies_to_mode(&g_options_registry[i], mode, for_binary_help);
211 option_descriptor_t *result = count ? SAFE_MALLOC(count * sizeof(*result), option_descriptor_t *) : NULL;
212 if (!result) {
213 *num_options = 0;
214 return NULL;
215 }
216 size_t out = 0;
217 for (size_t i = 0; i < g_registry_size; ++i)
218 if (registry_entry_applies_to_mode(&g_options_registry[i], mode, for_binary_help))
220 *num_options = out;
221 return result;
222}
bool registry_entry_applies_to_mode(const registry_entry_t *entry, asciichat_mode_t mode, bool for_binary_help)
Definition core.c:182
#define SAFE_MALLOC(size, cast)
static bool size_t gotel_query_t * out
Definition queries.h:8

◆ options_registry_get_for_mode()

const option_descriptor_t * options_registry_get_for_mode ( asciichat_mode_t mode,
size_t * num_options )

Get all options for a specific mode.

Returns an array of option descriptors that apply to the given mode. The array is allocated and must be freed by the caller.

Parameters
modeMode to filter by
num_optionsOUTPUT: Number of options returned
Returns
Array of option descriptors (caller must free), or NULL on error

Definition at line 181 of file public_api.c.

181 {
182 if (!num_options)
183 return NULL;
188 size_t count = 0;
189 for (size_t i = 0; i < g_registry_size; ++i)
190 count += (g_options_registry[i].mode_bitmask & mask) != 0;
191 option_descriptor_t *result = count ? SAFE_MALLOC(count * sizeof(*result), option_descriptor_t *) : NULL;
192 if (!result) {
193 *num_options = 0;
194 return NULL;
195 }
196 size_t out = 0;
197 for (size_t i = 0; i < g_registry_size; ++i)
198 if (g_options_registry[i].mode_bitmask & mask)
200 *num_options = out;
201 return result;
202}
option_mode_bitmask_t
Option mode bitmask.
Definition options.h:933
@ MODE_MCP_SERVER
Model Context Protocol rendering server.
Definition options.h:922
@ MODE_DISCOVERY_SERVICE
Discovery server mode - session management and WebRTC signaling.
Definition options.h:920
@ MODE_SERVER
Server mode - network server options.
Definition options.h:917
@ MODE_MIRROR
Mirror mode - local webcam viewing (no network).
Definition options.h:919
@ MODE_DISCOVERY
Discovery mode - participant that can dynamically become host.
Definition options.h:921
@ OPTION_MODE_DISCOVERY
Discovery mode (bit 4).
Definition options.h:939
@ OPTION_MODE_NONE
No modes (invalid).
Definition options.h:934
@ OPTION_MODE_MCP_SERVER
Definition options.h:940
@ OPTION_MODE_DISCOVERY_SVC
Discovery server mode (bit 3).
Definition options.h:938

◆ options_registry_get_input_type()

option_input_type_t options_registry_get_input_type ( const char * option_name)

Get input type for an option.

Retrieves the input type (OPTION_INPUT_ENUM, OPTION_INPUT_NUMERIC, etc.) for the given option.

Parameters
option_nameLong name of option
Returns
Input type (OPTION_INPUT_NONE if not found)

Definition at line 346 of file public_api.c.

346 {
347 if (!option_name) {
348 SET_ERRNO(ERROR_INVALID_PARAM, "Option name is NULL");
349 return OPTION_INPUT_NONE;
350 }
351
352 const option_metadata_t *meta = options_registry_get_metadata(option_name);
353 if (!meta) {
354 SET_ERRNO(ERROR_NOT_FOUND, "Option '%s' not found", option_name);
355 return OPTION_INPUT_NONE;
356 }
357
358 return meta->input_type;
359}
@ OPTION_INPUT_NONE
No input (boolean flag).
Definition builder.h:186

◆ options_registry_get_metadata()

const option_metadata_t * options_registry_get_metadata ( const char * long_name)

Get complete metadata for an option.

Retrieves all completion metadata for the given option, including enum values, numeric ranges, examples, input type, etc.

Parameters
long_nameLong name of option to look up
Returns
Pointer to metadata structure, or NULL if option not found
Note
The returned pointer points to data within the registry and should not be modified or freed.

Definition at line 251 of file public_api.c.

251 {
252 if (!long_name) {
253 SET_ERRNO(ERROR_INVALID_PARAM, "Long name is NULL");
254 return NULL;
255 }
256
257 // Look up option in registry and return its metadata
259 for (size_t i = 0; i < g_registry_size; i++) {
260 const registry_entry_t *entry = &g_options_registry[i];
261 if (entry->long_name && strcmp(entry->long_name, long_name) == 0) {
262 // Return the metadata from the registry entry
263 return &entry->metadata;
264 }
265 }
266
267 // If not found, return empty metadata
268 static option_metadata_t empty_metadata = {0};
269 return &empty_metadata;
270}
Registry entry - stores option definition with mode bitmask and metadata.
option_metadata_t metadata
Enum values, numeric ranges, examples.
const char * long_name

◆ options_registry_get_numeric_range()

bool options_registry_get_numeric_range ( const char * option_name,
int * min_out,
int * max_out,
int * step_out )

Get numeric range for an option.

Retrieves min/max/step values for an option that has OPTION_INPUT_NUMERIC type in its metadata.

Parameters
option_nameLong name of option
min_outOUTPUT: Minimum value (or 0 if no limit)
max_outOUTPUT: Maximum value (or 0 if no limit)
step_outOUTPUT: Step size (or 0 if continuous)
Returns
true if option found and has numeric range, false otherwise

Example:

int min, max, step;
if (options_registry_get_numeric_range("compression-level", &min, &max, &step)) {
printf("Range: %d-%d (step: %d)\n", min, max, step);
}
bool options_registry_get_numeric_range(const char *option_name, int *min_out, int *max_out, int *step_out)
Get numeric range for an option.
Definition public_api.c:302

Definition at line 302 of file public_api.c.

302 {
303 if (!option_name || !min_out || !max_out || !step_out) {
304 SET_ERRNO(ERROR_INVALID_PARAM, "Option name is NULL or min_out, max_out, or step_out is NULL");
305 return false;
306 }
307
308 const option_metadata_t *meta = options_registry_get_metadata(option_name);
309 if (!meta || meta->input_type != OPTION_INPUT_NUMERIC) {
310 *min_out = 0;
311 *max_out = 0;
312 *step_out = 0;
313 return false;
314 }
315
316 *min_out = meta->numeric_range.min;
317 *max_out = meta->numeric_range.max;
318 *step_out = meta->numeric_range.step;
319 return true;
320}
@ OPTION_INPUT_NUMERIC
Numeric value with optional min/max/step.
Definition builder.h:188
int max
Maximum value (or 0 if no limit).
Definition builder.h:210
int min
Minimum value (or 0 if no limit).
Definition builder.h:209
struct option_metadata_t::@061372117173071240020206164036331043262170062306 numeric_range
int step
Step size (0 = no step, continuous).
Definition builder.h:211

◆ registry_add_all_to_flags_builder()

asciichat_error_t registry_add_all_to_flags_builder ( flags_schema_builder_t * builder,
option_mode_bitmask_t mode_mask )

Populate a libflags schema builder from the application option registry.

Definition at line 84 of file public_api.c.

84 {
85 if (!builder)
86 return SET_ERRNO(ERROR_INVALID_PARAM, "Flags builder is NULL");
88 for (size_t i = 0; i < g_registry_size; ++i) {
89 const registry_entry_t *entry = &g_options_registry[i];
90 if (!entry->long_name || (entry->mode_bitmask != OPTION_MODE_NONE && !(entry->mode_bitmask & mode_mask) && !(entry->mode_bitmask & OPTION_MODE_BINARY)))
91 continue;
92 /* These binary commands are handled by ascii-chat's command dispatcher,
93 * not stored as values in options_t. */
94 if (entry->type == OPTION_TYPE_STRING && entry->default_value_size == 0 && entry->offset == 0)
95 continue;
96 flags_value_type_t type;
97 flags_option_behavior_t behavior = FLAGS_BEHAVIOR_VALUE;
98 switch (entry->type) {
100 type = FLAGS_TYPE_BOOL;
101 break;
102 case OPTION_TYPE_INT:
103 type = FLAGS_TYPE_INT64;
104 break;
106 type = FLAGS_TYPE_DOUBLE;
107 break;
109 type = FLAGS_TYPE_STRING;
110 break;
112 type = FLAGS_TYPE_CUSTOM;
113 behavior = FLAGS_BEHAVIOR_CALLBACK;
114 break;
116 type = FLAGS_TYPE_CUSTOM;
117 behavior = FLAGS_BEHAVIOR_ACTION;
118 break;
119 default:
120 continue;
121 }
122 flags_option_spec_t option = {.name = entry->long_name,
123 .short_name = entry->short_name,
124 .description = entry->help_text,
125 .group = entry->group,
126 .required = entry->required,
127 .metavar = entry->arg_placeholder,
128 .environment_name = entry->env_var_name,
129 .type = type,
130 .behavior = behavior,
131 .default_operation = entry->type == OPTION_TYPE_BOOL ? FLAGS_VALUE_TOGGLE : FLAGS_VALUE_ASSIGN,
132 .argument_requirement = entry->type == OPTION_TYPE_BOOL || entry->type == OPTION_TYPE_ACTION ? FLAGS_ARGUMENT_NONE
133 : entry->optional_arg ? FLAGS_ARGUMENT_OPTIONAL
134 : FLAGS_ARGUMENT_REQUIRED,
135 .storage_offset = entry->offset,
136 .storage_size = entry->type == OPTION_TYPE_STRING
137 ? (entry->owns_memory ? sizeof(char *) : (entry->default_value_size ? entry->default_value_size : OPTIONS_BUFF_SIZE))
138 : entry->type == OPTION_TYPE_DOUBLE ? (entry->default_value_size ? entry->default_value_size : sizeof(double))
139 : entry->type == OPTION_TYPE_BOOL ? (entry->default_value_size ? entry->default_value_size : sizeof(bool))
140 : (entry->default_value_size ? entry->default_value_size : sizeof(int)),
141 .default_value = entry->default_value,
142 .enum_values = entry->metadata.enum_values,
143 .enum_value_count = 0,
144 .dynamic_string = entry->owns_memory,
145 .parse = entry->type == OPTION_TYPE_CALLBACK ? registry_flags_parse : NULL,
146 .validate = entry->type == OPTION_TYPE_DOUBLE ? registry_flags_validate : NULL,
147 .validation_regex = entry->metadata.validation_pattern,
148 .on_change = entry->type == OPTION_TYPE_ACTION || (entry->type == OPTION_TYPE_STRING && entry->parse_fn) ? registry_flags_change : NULL,
149 .user_data = (void *)entry};
150 if (entry->type == OPTION_TYPE_CALLBACK || entry->type == OPTION_TYPE_ACTION)
151 option.storage_size = 0;
152 if (entry->metadata.enum_values) {
153 while (entry->metadata.enum_values[option.enum_value_count])
154 ++option.enum_value_count;
155 }
156 char config_key[256];
157 const char *config_field = entry->long_name;
158 if (entry->group && strcmp(entry->group, "OTEL") == 0 && strncmp(config_field, "otel-", 5) == 0)
159 config_field += 5;
160 if (entry->group && flags_config_make_toml_key(entry->group, config_field, config_key, sizeof(config_key)))
161 option.config_key = config_key;
162 if (!flags_schema_builder_add_option(builder, &option))
163 return SET_ERRNO(ERROR_MEMORY, "Failed to add %s to libflags schema", entry->long_name);
164 }
165 return ASCIICHAT_OK;
166}
@ OPTION_TYPE_INT
Integer value (–count 42).
Definition builder.h:172
@ OPTION_TYPE_DOUBLE
Floating point (–ratio 1.5).
Definition builder.h:174
@ OPTION_TYPE_STRING
String value (–name foo).
Definition builder.h:173
@ OPTION_TYPE_ACTION
Action that executes and may exit (–list-webcams, etc.).
Definition builder.h:176
@ OPTION_TYPE_CALLBACK
Custom parser function.
Definition builder.h:175
@ OPTION_TYPE_BOOL
Boolean flag (–flag, no value).
Definition builder.h:171
@ ERROR_MEMORY
Definition error_codes.h:55
#define OPTIONS_BUFF_SIZE
Buffer size for option string values.
Definition options.h:305
if(!queries||!out||index >=DATABASE_QUERY_COUNT) return false
option_type_t type
const char * group
bool optional_arg
bool required
bool owns_memory
size_t default_value_size
const char * help_text
option_mode_bitmask_t mode_bitmask
const char * arg_placeholder
Custom argument placeholder (e.g., "SHELL [FILE]" instead of "STR").
const char * env_var_name
char short_name
size_t offset

◆ registry_get_raw()

const registry_entry_t * registry_get_raw ( void )

Get raw access to registry for completions filtering.

Returns a pointer to the internal registry array. The array is NULL-terminated (final entry has long_name == NULL). Used by completions generators.

Returns
Pointer to registry array (read-only), or NULL on error

Definition at line 232 of file public_api.c.

232 {
234 return g_options_registry;
235}

References g_options_registry, and registry_init_size().