vld-clap
Clap integration for the vld validation library.
Validate CLI arguments after clap has parsed them — email format, URL, ranges, string lengths, regex patterns, and everything else vld supports. Validation rules go directly on the Cli struct via #[derive(Validate)].
Why
Clap handles argument parsing (types, defaults, required/optional), but doesn't validate semantic constraints like "must be a valid email" or "port must be 1–65535". vld-clap fills that gap — no separate schema struct needed.
Installation
[]
= "0.1"
= { = "0.1", = ["derive"] }
= { = "4", = ["derive"] }
= { = "1", = ["derive"] }
Quick Start
use Parser;
use Validate;
use *;
API
| Function | Description |
|---|---|
validate(args) |
Validate a struct with #[derive(Validate)] + Serialize |
validate_or_exit(args) |
Validate; print error & exit(2) on failure |
validate_with_schema::<S, T>(args) |
Validate T: Serialize against a separate schema S |
validate_json::<S>(json) |
Validate raw JSON |
Error Output
Invalid arguments:
--email: Invalid email address
--name: String must be at least 2 characters
--port: Number must be at most 65535
Examples
# Valid
# Invalid (exits with code 2)
License
MIT