ucp

Crates.ioucp
lib.rsucp
version0.1.0
sourcesrc
created_at2024-02-26 04:33:13.810962
updated_at2024-02-26 04:33:13.810962
descriptionCollection of Useful CLI Parsers
homepagehttps://gitlab.com/Kores/ucp
repositoryhttps://gitlab.com/Kores/ucp
max_upload_size
id1153011
size23,521
Jonathan (JonathanxD)

documentation

https://docs.rs/ucp/

README

Useful CLI Parsers (UCP)

This crate provides a set of parsers for command line interfaces (CLI).

Examples

Nothing explains better than examples.

use ucp::pred::{Comparison, FieldComparison, Operator};

fn main() {
    assert_eq!(
        ">=1024".parse::<Comparison<usize>>(),
        Ok(Comparison::new(Operator::Gte, 1024))
    );

    assert_eq!(
        "!1024".parse::<Comparison<usize>>(),
        Ok(Comparison::new(Operator::Ne, 1024))
    );

    assert_eq!(
        "size=1024".parse::<FieldComparison<String, usize>>(),
        Ok(FieldComparison::new(
            String::from("size"),
            Operator::Eq,
            1024
        )),
    );

    assert_eq!(
        "sizeā‰ 1024".parse::<FieldComparison<String, usize>>(),
        Ok(FieldComparison::new(
            String::from("size"),
            Operator::Ne,
            1024
        )),
    );
}

Note

I made this crate to simplify the process of making cli tools (which I do a lot for myself), it's intended to be used with clap and has no specialized Error type for parsing failures, String was used instead.

This may change in the next versions of the crate and will break compatibility with previous versions.

Commit count: 0

cargo fmt