xarp
A zero-dependency, pure-Rust argument parser with rich 24-color and RGB terminal styling.
Installation
Add this to your Cargo.toml:
[]
= "0.1.2"
Quick Start
use ;
Argument Types
- Flags: Set
action(ArgAction::SetTrue). Checks viamatches.get_flag("id"). - Options: Default action (
ArgAction::Set). Value passed via--opt valueor--opt=value. Repeated use keeps the last value; a following--is never consumed as a value. - Positional Arguments: Omit both
.short()and.long(). Evaluated in declaration order. Only the last positional may useArgAction::Appendto collect multiple values. - Multiple Values: Use
action(ArgAction::Append)and retrieve viamatches.get_many::<T>("id").
let matches = new
.arg
.get_matches;
if let Some = matches.
Validation & Fallbacks
use ;
let matches = new
.arg
.arg
.arg
.get_matches;
Conflict checks consider explicitly passed arguments (CLI or environment),
never default_values. A required positional must not follow an optional one.
Typed Values & Errors
get_one returns None for both missing and unparsable values. Use
try_get_one / try_get_many to tell them apart:
let port: u16 = matches.try_get_one.unwrap.unwrap_or;
Parse failures from try_get_* carry the same --help guidance as other
parse errors.
Parsing Without Exiting
get_matches() prints help/version and exits the process. Library code
should use a try_ variant and handle XarpError itself:
use ;
let result = new
.arg
.try_get_matches;
match result
try_get_matches_with_env(&args, &env_map) parses with an explicit
environment map instead of the process environment, which keeps tests
deterministic. Tokens after -- are always positionals.
Subcommands
Subcommands are nested Xarp instances:
use ;
Terminal Styling & Colors
xarp provides a self-contained ANSI coloring engine supporting 24 named palette colors, 8-bit ANSI 256, and 24-bit TrueColor (RGB).
use ;
use Effects;
use Style;
// Using preset styles
println!;
println!;
// Custom builder styles
let warning = new
.bold
.fg
.bg;
println!;
// TrueColor (RGB) and 256-color support
let rgb_style = new.fg;
let ansi_style = new.fg;
// Operator overloading
let alert = BrightRed | BOLD | UNDERLINE;
println!;
Styles compose with | as well (Style | Style merges, right-hand colors
win). Help output follows the configured Styles theme; setting the
NO_COLOR environment variable (any value, including empty) disables colors.
License
Dual-licensed under either of:
- MIT License
- Apache License, Version 2.0