8 unstable releases (3 breaking)

0.5.0 Apr 4, 2024
0.4.6 Oct 10, 2023
0.4.3 Sep 23, 2023
0.4.1 Jul 22, 2023
0.2.2 Dec 30, 2022

#126 in Command-line interface

Download history 23/week @ 2024-02-20 21/week @ 2024-02-27 18/week @ 2024-03-12 1/week @ 2024-03-26 153/week @ 2024-04-02 7/week @ 2024-04-09

944 downloads per month
Used in findsource

MPL-2.0 license

775KB
20K SLoC

Cote

A simple option manager manage the AOpt, support auto generate help message.

Setup

cargo add cote

Enable Features from aopt

Enable sync feature

If you want the utils of current crate implement Send and Sync, you can enable sync feature.

[dependencies]
cote = { version = "*", features = [ "sync" ] }

Documents

See reference for more information.

Example

Using 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(())
}

LICENSE

MPL-2.0

Dependencies

~3.5MB
~62K SLoC