Crates.io | cliply |
lib.rs | cliply |
version | 0.2.0 |
source | src |
created_at | 2023-07-08 20:30:50.042963 |
updated_at | 2023-08-04 14:31:30.488963 |
description | Making command-line interfaces in Rust easy. |
homepage | https://github.com/angeldollface/cliply |
repository | https://github.com/angeldollface/cliply |
max_upload_size | |
id | 911666 |
size | 29,568 |
Making command-line interfaces in Rust easy.
Cliply is an alterantive to the popular clap
library for parsing and processing command-line arguments. It is intended to be a little more friendly for people who are only just learning Rust. Enjoy!
-h
or --help
flag out of the box.-v
or --version
flag out of the box.To use Cliply in your Rust project add this line to your project's Cargo.toml
's [dependencies]
section:
cliply = "0.2.0"
To import the library into your project's code, use this line:
use cliply::App;
To find out exactly how to use the library please read the section below.
An example of how to use Cliply's APIs in a sample app can be viewed below:
/*
CLIPLY by "Angel Dollface".
Licensed under the MIT license.
*/
/// Importing the main
/// Cliply API struct.
use cliply::App;
/// Importing the error
/// struct to handle any
/// errors.
use cliply::CliplyError;
/// Main point of
/// entry for the
/// Rust compiler.
pub fn main() -> () {
// Instantiating the "App" struct with the required
// data.
let mut my_app: App = App::new(
&"Test App",
&"1.0.0",
&"Angel Dollface"
);
// Adding a greeting without data. Note the use of "false".
my_app.add_arg(
&"greet",
&" generic greeting for the user",
&"false"
);
// Adding a greeting with data. Note the use of "true".
my_app.add_arg(
&"cgreet",
&"custom greeting for the user",
&"true"
);
// Was the version flag used?
if my_app.version_is() == true {
println!("{}", my_app.version_info());
}
// Was the help flag used?
else if my_app.help_is() == true {
println!("{}", my_app.help_info());
}
// Was the "greet" flag used?
else if my_app.arg_was_used(&"greet") == true {
println!("Hello World!");
}
// Was the "cgreet" flag used? Note the use of the result!
else if my_app.arg_was_used(&"cgreet") == true {
let arg_data: Result<String, CliplyError> = my_app.get_arg_data(&"cgreet");
match arg_data {
Ok(x) => {
println!("Hello, {}!", x);
},
Err(e) => {
println!("{}", e.to_string());
}
}
}
// If user-supplied flags are invalid, show
// them the app's help message.
else {
println!("{}", my_app.help_info());
}
}
If you would like to read detailed documentation, you can do so by visiting this link.
coutils
crate.