| Crates.io | cote |
| lib.rs | cote |
| version | 0.17.1 |
| created_at | 2022-12-19 13:44:03.12371+00 |
| updated_at | 2025-06-22 11:43:40.223121+00 |
| description | Quickly build your command line utils |
| homepage | |
| repository | https://github.com/araraloren/aopt/ |
| max_upload_size | |
| id | 741250 |
| size | 209,754 |
A simple option manager manage the AOpt, support auto generate help message.
cargo add cote
sync featureIf you want the utils of current crate implement Send and Sync, you can enable sync feature.
[dependencies]
cote = { version = "*", features = [ "sync" ] }
See reference for more information.
Cote generate struct from command line options.use aopt::opt::Pos;
use cote::prelude::*;
fn main() -> cote::Result<()> {
#[derive(Debug, Cote)]
pub struct Cli {
/// A flag option named `--flag`
flag: bool,
/// Comment here set the help message for option
#[arg(alias = "-n")]
name: String,
#[arg(help = "`Option` mean the option is not force required")]
nick: Option<String>,
/// A position option at index 1
#[arg(index = "1")]
from: Pos<String>,
/// A positon option collect argument start from 2
#[pos(index = 2..)]
to: Vec<String>,
}
let cli = Cli::parse(Args::from(["app", "-nLily", "src", "foo", "bar"]))?;
assert!(!cli.flag);
assert_eq!(cli.name, String::from("Lily"));
assert_eq!(cli.nick, None);
assert_eq!(cli.from, Pos(String::from("src")));
assert_eq!(cli.to, vec![String::from("foo"), String::from("bar")]);
let cli = Cli::parse(Args::from(["app", "--name", "Lily", "src", "foo", "bar"]))?;
assert!(!cli.flag);
assert_eq!(cli.name, String::from("Lily"));
assert_eq!(cli.nick, None);
assert_eq!(cli.from, Pos(String::from("src")));
assert_eq!(cli.to, vec![String::from("foo"), String::from("bar")]);
assert!(Cli::parse(Args::from(["app", "--nick", "Lily", "src", "foo", "bar"])).is_err());
Ok(())
}
MPL-2.0