A builder-style command-line argument parser for Odin, in the spirit of Rust's
clap. Supports subcommands and a fluent builder API, neither of which
core:flags provides.
If you need a flat, quick CLI, use core:flags. Use argus when you need
subcommands or prefer building the arg spec in code.
v0.0.1. Scope is "core:flags parity on flat flags, plus one level of subcommands, via a builder API". See TODO for the roadmap.
Odin-style only:
-namesets a bool flag.-name:valuesets a typed option (string, int, float).- The first bare token matching a registered subcommand switches parsing to that subcommand. Max depth is one level.
- Other bare tokens fill registered positionals in order.
-helpand-hrequest help.
No Unix-style --flag value, no short clustering.
package main
import cli "path/to/argus/cli"
import "core:os"
main :: proc() {
cmd := cli.command("mytool", "does a thing")
cli.flag(&cmd, "verbose", "verbose", "verbose output")
cli.opt(&cmd, "output", "output", .String, "output file", default = "out.txt")
build := cli.subcommand(&cmd, "build", "builds the project")
cli.flag(build, "release", "release", "build in release mode")
defer cli.command_destroy(&cmd)
m := cli.parse_or_exit(cmd, os.args[1:], os.to_writer(os.stdout))
defer cli.destroy(&m)
if cli.has_subcommand(m, "build") {
release := cli.get_bool(m.sub^, "release")
if release {
// build in release mode
}
}
}parse creates and owns a virtual.Arena inside the returned Matches.
Everything the result needs lives in that arena. Call cli.destroy(&m) once
when done. The Command spec is caller-owned; free it with
cli.command_destroy(&cmd).
parse returns (Matches, Error) for callers that want to handle errors
themselves. parse_or_exit prints and exits: 0 on help, 2 on any usage or
validation error.
odin test cli
odin build examples/mytool -out:/tmp/mytool
MIT. See LICENSE.