Expand description
§Clier
§Command Line Argument Parser for Rust
Clier
is a command line argument parser and command framework for rust.
§Parser
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",
},
}
§Framework
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();
}
Modules§
- builder
- Structs for easliy building entities describing the commands and flags.
- display
- Struct for interface/ui of app.
- error
- Error enum
- hooks
- Hooks for runtime of app, inspired by react.
- run
- Run
Macros§
- cmd
macros
- Short for generating command with Command::new
Structs§
- Argv
- Example structure:
- CliMeta
- Should be used when describing your cli app, this will show up in your help message
- Clier
- Clier is the main struct for the framework
- CmdCollection
- .
- CmdMeta
- testing
- HasMeta
- Typestate pattern: State for (CliMeta)
- Missing
Meta - Typestate pattern: State for (CliMeta)
- NotRunnable
- Symbolises when clier is not runnable.
- Runnable
- This means clier is runnable
Enums§
- Commands
- Commands