yeah, clap can be used without the env
cargo devel CI / cargo CI (push) Successful in 3m29s Details

This commit is contained in:
Christoph J. Scherr 2024-06-28 17:08:36 +02:00
parent ca1e307571
commit 938af23be9
4 changed files with 27 additions and 1 deletions

7
Cargo.lock generated
View File

@ -304,6 +304,13 @@ dependencies = [
"clap_derive",
]
[[package]]
name = "clap-repl-demo"
version = "0.1.0"
dependencies = [
"clap",
]
[[package]]
name = "clap_builder"
version = "4.5.7"

View File

@ -25,7 +25,7 @@ members = [
"members/diesel-demo",
"members/ptlog",
"members/hello-world",
"members/statusline",
"members/statusline", "members/clap-repl-demo",
]
default-members = [
".",

View File

@ -0,0 +1,7 @@
[package]
name = "clap-repl-demo"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.5.7", features = ["derive"] }

View File

@ -0,0 +1,12 @@
use clap::{arg, command, value_parser, ArgAction, Command};
fn main() {
// define a command with clap builder
let cmdtest = Command::new("test").arg(arg!(--foo <VALUE>).required(true));
// instead of using the args that were actually given to the executable, we just insert our own
// vec
let simulated_input = vec!["test", "--foo", "5"];
let parsed = cmdtest.try_get_matches_from(simulated_input);
dbg!(&parsed);
}