Crates.io | cleasy |
lib.rs | cleasy |
version | 1.0.0 |
source | src |
created_at | 2022-04-17 20:56:09.540742 |
updated_at | 2022-04-17 20:56:09.540742 |
description | Making command-line interfaces in Rust easy. |
homepage | https://github.com/iamtheblackunicorn/cleasy |
repository | https://github.com/iamtheblackunicorn/cleasy |
max_upload_size | |
id | 569587 |
size | 13,297 |
Making command-line interfaces in Rust easy.
I've been writing an awful lot of command line applications in Rust lately. I'm sick and tired of manually parsing the options passed to my programs, so I decided to write a library to make my life easier. I know clap
would have been option but I don't like drama. clap
is drama I am not too keen to get into right now.
-h
or --help
flag out of the box.-v
or --version
flag out of the box.To use Cleasy in your rust project, add this line to your project's Cargo.toml
's [dependencies]
section:
cleasy = { git = "https://github.com/iamtheblackunicorn/cleasy", version = "1.0.0" }
To import the library into your project's code, use this line:
use cleasy::App;
To find out exactly how to use the library, please check out the section below.
An example using all of Cleasy's APIs can be found in the sample below:
/*
CLEASY by Alexander Abraham,
a.k.a. "Angeldust Duke" a.k.a. "The Black Unicorn".
Licensed under the MIT license.
*/
use cleasy::App;
fn main(){
/// Name, version, and author data.
let name: String = String::from("Test App");
let version: String = String::from("1.0.0");
let author: String = String::from("Alexander Abraham");
/// Instantiating the "App" struct with the required
/// data.
let mut my_app: App = App::new(name, version, author);
/// Adding a greeting without data. Note the use of "false".
my_app.add_arg("greet".to_string(), "generic greeting for the user".to_string(), "false".to_string());
/// Adding a greeting with data. Note the use of "true".
my_app.add_arg("cgreet".to_string(), "custom greeting for the user".to_string(), "true".to_string());
if my_app.version_is() == true {
println!("{}", my_app.version());
}
else if my_app.help_is() == true {
println!("{}", my_app.help());
}
else if my_app.arg_was_used("greet".to_string()) == true {
println!("Hello World!");
}
else if my_app.arg_was_used("cgreet".to_string()) == true {
let arg_data: String = my_app.get_arg_data("cgreet".to_string());
println!("Hello, {}!", arg_data);
}
else {
println!("{}", my_app.help());
}
}