yeah, clap can be used without the env
cargo devel CI / cargo CI (push) Successful in 3m29s
Details
cargo devel CI / cargo CI (push) Successful in 3m29s
Details
This commit is contained in:
parent
ca1e307571
commit
938af23be9
|
@ -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"
|
||||
|
|
|
@ -25,7 +25,7 @@ members = [
|
|||
"members/diesel-demo",
|
||||
"members/ptlog",
|
||||
"members/hello-world",
|
||||
"members/statusline",
|
||||
"members/statusline", "members/clap-repl-demo",
|
||||
]
|
||||
default-members = [
|
||||
".",
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "clap-repl-demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.7", features = ["derive"] }
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue