10 个版本
| 0.5.2 | 2024年8月7日 | 
|---|---|
| 0.5.1 | 2024年7月30日 | 
| 0.5.0 | 2024年4月4日 | 
| 0.4.6 | 2023年10月10日 | 
| 0.2.2 |  | 
#268 in 命令行界面
255 每月下载量
用于 findsource
775KB
 20K  SLoC
Cote
Cote 是一个简单的选项管理器,用于管理 AOpt,支持自动生成帮助信息。
配置
cargoadd cote
启用 aopt 的功能
启用 sync 功能
如果你想让当前库的工具实现 Send 和 Sync,你可以启用 sync 功能。
[dependencies]
cote = { version = "*", features = [ "sync" ] }
文档
更多信息请参阅 reference。
示例
使用 Cote 从命令行选项生成结构体。
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
依赖
~1.8–2.6MB
~44K SLoC