Files
wehub-resource-sync e7738de6d2
CI / Deep Native Runtime Cases (1/6) (push) Has been skipped
CI / Native Preflight (push) Failing after 1s
CI / Native Runtime Cases (1/2) (push) Failing after 0s
CI / Native Runtime Cases (2/2) (push) Failing after 1s
CI / Native Metadata Reports (push) Failing after 0s
CI / Native Direct Backend Artifacts (push) Failing after 0s
CI / Native Sanitizer Smoke (push) Failing after 1s
CI / Command Contract Snapshots (push) Failing after 1s
CI / Deep Conformance Suite (push) Has been skipped
CI / Graph Build Perf (push) Failing after 1s
CI / Deep Native Preflight (push) Has been skipped
CI / Deep Native Runtime Cases (2/6) (push) Has been skipped
CI / Deep Native Runtime Cases (3/6) (push) Has been skipped
CI / Conformance Suite (push) Failing after 1s
CI / Workspace Checks (push) Failing after 0s
CI / Deep Native Runtime Cases (5/6) (push) Has been skipped
CI / Deep Native Runtime Cases (6/6) (push) Has been skipped
CI / Deep Native Runtime Cases (4/6) (push) Has been skipped
CI / Deep Graph Build Perf (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:29:30 +08:00

47 lines
1.7 KiB
Markdown

## When To Use std.args
In Zerolang, use `std.args` for hosted command-line programs that need positional
arguments, option lookup, or simple numeric argument parsing.
Runnable today:
| API | Return | Notes |
| --- | --- | --- |
| `std.args.len()` | `usize` | Returns the process argument count. |
| `std.args.get(index)` | `Maybe<String>` | Returns the argument at `index` when present. |
| `std.args.has(index)` | `Bool` | Reports whether `index` has an argument. |
| `std.args.getOr(index, fallback)` | `String` | Returns the argument or a caller-provided fallback. |
| `std.args.find(name)` | `Maybe<usize>` | Finds the first exact argument match after the executable path. |
| `std.args.valueAfter(name)` | `Maybe<String>` | Returns the argument immediately after a matched option name. |
| `std.args.parseU32(index)` | `Maybe<u32>` | Parses an indexed argument as `u32`. |
Current limits:
- Iterator-style argument APIs.
- Target diagnostics for platforms without process arguments.
## Example
```zero
pub fn main(world: World) -> Void raises {
let count: usize = std.args.len()
let first: String = std.args.getOr(1, "default")
let maybe_count: Maybe<u32> = std.args.parseU32(2)
if count > 2 && maybe_count.has {
check world.out.write(first)
check world.out.write("\n")
}
}
```
## Design Notes
The module is hosted-only. Freestanding, edge, and embedded targets should
reject it unless they explicitly provide an argument capability.
On native Windows-style targets, `std.args` is byte-oriented process input. It
is not a Unicode argv normalization layer.
Programs that need portable argument semantics should keep target-specific
decoding outside the target-neutral core.