optparse

Rich CLI Option Parser

Functions

FunctionDescription
_opt_copy
_opt_streq
_opt_strlen
opt_newCreate new option parser with max options.
opt_addAdd an option. short=0 for no short flag. has_val=1 if takes value.
_opt_find_longInternal: find option by long name. Returns index or -1.
_opt_find_shortInternal: find option by short flag. Returns index or -1.
opt_parseParse command-line arguments. argc/argv from os_argv(). Returns 0 on success,…
opt_getGet option value. Copies value to out, returns length. 0 if not found.
opt_hasCheck if option was provided. Returns 1 or 0.
opt_positionalGet positional argument at index. Copies to out, returns length.
opt_nposNumber of positional arguments found.
opt_helpPrint help message to stdout.

Details

_opt_copy

fn _opt_copy(dst: &i8, doff: i64, src: &i8, soff: i64, n: i64)

_opt_streq

fn _opt_streq(a: &i8, aoff: i64, alen: i64, b: &i8, boff: i64, blen: i64) -> i64

_opt_strlen

fn _opt_strlen(s: &i8) -> i64

opt_new

fn opt_new(max: i64) -> &i64

Create new option parser with max options.

opt_add

fn opt_add(p: &i64, name: &i8, nlen: i64, short: i64, has_val: i64, required: i64, desc: &i8, dlen: i64)

Add an option. short=0 for no short flag. has_val=1 if takes value.

_opt_find_long

fn _opt_find_long(p: &i64, name: &i8, nlen: i64) -> i64

Internal: find option by long name. Returns index or -1.

_opt_find_short

fn _opt_find_short(p: &i64, ch: i64) -> i64

Internal: find option by short flag. Returns index or -1.

opt_parse

fn opt_parse(p: &i64, argc: i64, argv: &i64) -> i64

Parse command-line arguments. argc/argv from os_argv(). Returns 0 on success, -1 if required option missing.

opt_get

fn opt_get(p: &i64, name: &i8, nlen: i64, out: &i8) -> i64

Get option value. Copies value to out, returns length. 0 if not found.

opt_has

fn opt_has(p: &i64, name: &i8, nlen: i64) -> i64

Check if option was provided. Returns 1 or 0.

opt_positional

fn opt_positional(p: &i64, idx: i64, out: &i8) -> i64

Get positional argument at index. Copies to out, returns length.

opt_npos

fn opt_npos(p: &i64) -> i64

Number of positional arguments found.

opt_help

fn opt_help(p: &i64)

Print help message to stdout.