From 57a9f56084de9183b2ab0880de5b8da2932d1a13 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Thu, 10 Nov 2022 11:37:00 +0000 Subject: [PATCH] Setup a basic clap cli --- Cargo.lock | 36 ++++++------------------------------ Cargo.toml | 4 ++-- src/main.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- src/state.rs | 13 +++++++++++++ 4 files changed, 67 insertions(+), 34 deletions(-) create mode 100644 src/state.rs diff --git a/Cargo.lock b/Cargo.lock index 6482c4d..9a10d8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,26 +51,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.23" +version = "4.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3" dependencies = [ "heck", "proc-macro-error", @@ -81,9 +79,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -161,12 +159,6 @@ dependencies = [ "url", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "heck" version = "0.4.0" @@ -192,16 +184,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "jobserver" version = "0.1.25" @@ -489,12 +471,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 9db1990..f181fa0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" [dependencies] ansi_term = "0.12.1" -clap = { version = "3.2.23", features = ["derive"] } +clap = { version = "4.0.18", features = ["derive"] } git2 = "0.15" rayon = "1.5" spinners = "4.1.0" -log = "0.4" \ No newline at end of file +log = "0.4" diff --git a/src/main.rs b/src/main.rs index e7a11a9..7ed5736 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,47 @@ -fn main() { - println!("Hello, world!"); +use clap::{Parser, Subcommand}; +use std::path::PathBuf; + +pub mod state; + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Cli { + /// Sets a custom config file + #[arg(short, long, value_name = "FILE")] + config: Option, + + /// Turn debugging information on + #[arg(short, long, action = clap::ArgAction::Count)] + debug: u8, + + #[command(subcommand)] + command: Option, +} + +#[derive(Subcommand)] +enum Commands { + /// does testing things + Test { + /// lists test values + #[arg(short, long)] + list: bool, + }, +} + +fn main() { + let cli = Cli::parse(); + // You can check for the existence of subcommands, and if found use their + // matches just as you would the top level cmd + match &cli.command { + Some(Commands::Test { list }) => { + if *list { + println!("Printing testing lists..."); + } else { + println!("Not printing testing lists..."); + } + } + None => { + println!("Hello, world!!!!"); + } + } } diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..6739c56 --- /dev/null +++ b/src/state.rs @@ -0,0 +1,13 @@ +use std::cell::Ref; + +use git2::Repository; + +pub struct State<'a> { + repo: &'a Repository, +} + +impl State<'a> { + pub fn new(repo: &Repository) -> Self { + Self { repo } + } +}