diff --git a/subcommand/Cargo.lock b/subcommand/Cargo.lock index 207cfde..e35023c 100644 --- a/subcommand/Cargo.lock +++ b/subcommand/Cargo.lock @@ -27,11 +27,26 @@ checksum = "2148adefda54e14492fb9bddcc600b4344c5d1a3123bd666dcb939c6f0e0e57e" dependencies = [ "atty", "bitflags", + "clap_derive", "clap_lex", + "once_cell", "strsim", "termcolor", ] +[[package]] +name = "clap_derive" +version = "4.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "clap_lex" version = "0.3.0" @@ -41,6 +56,12 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -56,12 +77,60 @@ version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + [[package]] name = "os_str_bytes" version = "6.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5bf27447411e9ee3ff51186bf7a08e16c341efdde93f4d823e8844429bed7e" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + [[package]] name = "strsim" version = "0.10.0" @@ -75,6 +144,17 @@ dependencies = [ "clap", ] +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "termcolor" version = "1.1.3" @@ -84,6 +164,18 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "winapi" version = "0.3.9" diff --git a/subcommand/Cargo.toml b/subcommand/Cargo.toml index d2c2575..6a8a793 100644 --- a/subcommand/Cargo.toml +++ b/subcommand/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "4.0.26" +clap = { version = "4.0.26", features = ["derive"] } diff --git a/subcommand/src/main.rs b/subcommand/src/main.rs index a10ac90..c0590f1 100644 --- a/subcommand/src/main.rs +++ b/subcommand/src/main.rs @@ -1,8 +1,12 @@ +// This doesnt works: + use clap::Arg; use clap::Command; fn main() { let command = Command::new("example") + .subcommand_required(true) + .allow_external_subcommands(true) .arg( Arg::new("working_directory") .short('w') @@ -18,8 +22,38 @@ fn main() { match matches.subcommand() { Some(("run", _sub_matches)) => println!("It's run"), + Some((ext, _sub_matches)) => println!("Finding if we have a \"{ext}\" command"), _ => { println!("Finding out if it an external command...") } } } + +// This doesn't work + +// use std::path::{Path, PathBuf}; + +// use clap::{Parser, Subcommand}; + +// #[derive(Parser)] +// #[command(version)] +// struct Cli { +// #[arg(short, long)] +// working_directory: Option, + +// #[command(subcommand)] +// command: Command, +// } + +// #[derive(Subcommand)] +// enum Command { +// Run { cases: Option> }, +// } + +// fn main() { +// let cli = Cli::parse(); +// match &cli.command { +// Command::Run { cases } => println!("Running cases: {:?}", cases), +// _ => println!("External"), +// } +// }