Simple Clap CLI Implementation

Added clap as a dependency to built the CLI in order to test the image crate through a simple to use command
This commit is contained in:
Víctor Martínez 2020-11-22 02:08:21 +01:00
parent 9011440afe
commit 49c915ef6b
8 changed files with 61 additions and 0 deletions

5
.gitignore vendored
View file

@ -8,3 +8,8 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# Added by cargo
/target

14
Cargo.toml Normal file
View file

@ -0,0 +1,14 @@
[package]
name = "imgffs"
version = "0.1.0"
authors = ["Víctor Martínez <victorcoder2@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "lib"
[dependencies]
image = "0.23.12"
clap = "2.33.3"

BIN
mock/beach.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

BIN
mock/chair.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
mock/tree.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

28
src/cli/mod.rs Normal file
View file

@ -0,0 +1,28 @@
use clap::{App, Arg};
const HELP_TEMPLATE: &str = "{bin} v{version}
-----------
{about}
{all-args}
-----------
(C) 2020 {author}
{after-help}";
/// This function builds the Command Line Application
/// already with its metadata, args boundaries etc.
pub fn build_cli() -> App<'static, 'static> {
App::new("Image Editor application")
.author(crate_authors!())
.version(crate_version!())
.about("Edit, transform, crop, rotate etc. an image with just one command")
.template(HELP_TEMPLATE)
.before_help("Thanks for using this app bro :)")
.after_help("Have a nice day!")
.arg(Arg::with_name("FILE").index(1).required(true))
}

4
src/lib.rs Normal file
View file

@ -0,0 +1,4 @@
#[macro_use]
extern crate clap;
pub mod cli;

10
src/main.rs Normal file
View file

@ -0,0 +1,10 @@
extern crate clap;
extern crate image;
use lib::cli;
fn main() {
let matches = cli::build_cli().get_matches();
}