Argv access and flag parsing for fastC.
Part of the fastc-core launch set. The implementation currently ships
inside the fastC compiler's built-in prelude — every fastC v1.0
program already gets use cli::* for free. This repository is the
public home for the module's API and will become installable via
fastc add github.com/Skelf-Research/fastc-core-cli once stage 1.7's
vendor-consumption flow completes the loop.
use cli::count; // i32 — argv count, including argv[0]
use cli::arg_at; // (i: i32) -> raw(u8) — argv[i], null when OOB
use cli::program_name; // raw(u8) — argv[0]
use cli::has_flag; // (name: raw(u8)) -> bool
use cli::flag_value; // (name: raw(u8)) -> raw(u8) — null if absent
use cli::flag_int; // (name: raw(u8), fallback: i32) -> i32
use cli::is_null; // (p: raw(u8)) -> bool
use cli::null_arg; // () -> raw(u8) — the NULL sentinel
Flag forms accepted (first match wins, later duplicates ignored):
--name=value (one-token, `=` separator)
--name value (two-token, consumes the next argv slot)
use cli::flag_int;
use cli::flag_value;
use cli::is_null;
use io::println;
use io::print_int;
use io::put_char;
fn main() -> i32 {
let n: i32 = flag_int(cstr("count"), 1);
let name: raw(u8) = flag_value(cstr("name"));
if (is_null(name)) {
println(cstr("(no --name)"));
}
print_int(n);
put_char(10);
return 0;
}
Argv is read-only process state the OS hands you. v1 treats it as
ambient like stdin — no Cap* token required. A CapArgs token
may be added if the threat model around argv-injection tightens.
v0.1.0 — preview. API is final; the package becomes a true
installable via fastc add once the consumption flow ships. Until
then, the same API is available in every fastC v1.0 program via
the built-in prelude.
MIT