Crates.io | clier |
lib.rs | clier |
version | 0.7.4 |
source | src |
created_at | 2023-08-21 18:37:55.295065 |
updated_at | 2024-05-22 20:30:40.936842 |
description | A cli parser and framework for rust |
homepage | |
repository | https://github.com/vincent-thomas/clier |
max_upload_size | |
id | 950342 |
size | 31,194 |
Clier
is a command line argument parser and command framework for rust.
To start a new cli projects run:
$ cargo new demo
$ cargo add clier
Then define your CLI in main.rs
:
use clier_parser::Argv;
let args: Argv = Argv::parse();
println!("{:#?}", args);
And try it out:
$ cargo run -- command subcommand --test=value --no-production --help --try-me=false
Argv {
commands: [
"command",
"subcommand",
],
flags: {
"test": "value",
"production": "false",
"help": "true",
"try-me": "false",
},
}
use clier::run::ExitCode;
use clier::{CliMeta, Clier, CmdCollection, CmdMeta, Commands};
fn main() {
let clier_builder = Clier::parse().meta(CliMeta {
name: "example-clier".into(),
usage: Some("[command]".into()),
description: "testing".into(),
version: Some((0, 0, 0))
});
let app = clier_builder.runnable(vec![Commands::Collection(CmdCollection {
meta: CmdMeta::new("testing", "testing"),
children: Box::from([Commands::Command {
meta: CmdMeta::new("testchild", "testing"),
handler: |_| {
println!("hello");
ExitCode(0)
}
}])
})]);
app.run();
}