From 0d94de70e16a807acbe145306b53d44a7e2488b1 Mon Sep 17 00:00:00 2001 From: lovebird Date: Tue, 12 Nov 2024 21:57:02 +0100 Subject: [PATCH] cli min --- ref/cli/.gitignore | 14 ++++++++++++++ ref/cli/Cargo.toml | 15 +++++++++++++++ ref/cli/LICENSE-MIT.md | 21 +++++++++++++++++++++ ref/cli/README.md | 12 ++++++++++++ ref/cli/src/cli.rs | 21 +++++++++++++++++++++ ref/cli/src/main.rs | 5 +++++ 6 files changed, 88 insertions(+) create mode 100644 ref/cli/.gitignore create mode 100644 ref/cli/Cargo.toml create mode 100644 ref/cli/LICENSE-MIT.md create mode 100644 ref/cli/README.md create mode 100644 ref/cli/src/cli.rs create mode 100644 ref/cli/src/main.rs diff --git a/ref/cli/.gitignore b/ref/cli/.gitignore new file mode 100644 index 0000000..7f7be13 --- /dev/null +++ b/ref/cli/.gitignore @@ -0,0 +1,14 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# IDEs +.vscode/ +.idea/ diff --git a/ref/cli/Cargo.toml b/ref/cli/Cargo.toml new file mode 100644 index 0000000..b6e91b5 --- /dev/null +++ b/ref/cli/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cli" +version = "0.1.0" +authors = ["lovebird "] +edition = "2018" +license-file = "LICENSE-MIT.md" +readme = "README.md" + +[dependencies] +clap = "2.33.0" + +[profile.release] +opt-level = 'z' +lto = true +panic = 'abort' diff --git a/ref/cli/LICENSE-MIT.md b/ref/cli/LICENSE-MIT.md new file mode 100644 index 0000000..dffd547 --- /dev/null +++ b/ref/cli/LICENSE-MIT.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 lovebird + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ref/cli/README.md b/ref/cli/README.md new file mode 100644 index 0000000..eb4acf6 --- /dev/null +++ b/ref/cli/README.md @@ -0,0 +1,12 @@ +# Rust cli boilerplate. + +Contains [clap](https://clap.rs/) for arguments parsing and nothing else. + +# How to use this boilerplate? + +- Replace name, authors etc in [Cargo.toml](./Cargo.toml) and you are good to go. + +- Using cargo [generate](https://github.com/ashleygwilliams/cargo-generate). +```sh +cargo generate --git https://github.com/pjmp/rust-cli-boilerplate.git +``` diff --git a/ref/cli/src/cli.rs b/ref/cli/src/cli.rs new file mode 100644 index 0000000..c8a1755 --- /dev/null +++ b/ref/cli/src/cli.rs @@ -0,0 +1,21 @@ +use clap::{ + crate_authors, /* , Arg */ + crate_description, crate_name, crate_version, App, AppSettings, +}; + +pub fn new() -> App<'static, 'static> { + App::new(crate_name!()) + .version(crate_version!()) + .about(crate_description!()) + .author(crate_authors!()) + .setting(AppSettings::ArgRequiredElseHelp) + .setting(AppSettings::ColorAuto) + // .arg( + // Arg::with_name("option") + // .short("o") + // .long("option") + // .help("option description") + // .takes_value(true) + // .value_name("opts"), + // ) +} diff --git a/ref/cli/src/main.rs b/ref/cli/src/main.rs new file mode 100644 index 0000000..30978ba --- /dev/null +++ b/ref/cli/src/main.rs @@ -0,0 +1,5 @@ +mod cli; + +fn main() { + let _app = cli::new().get_matches(); +}