Skip to content

Clap 3 Beta: Add default values using @args macro #2034

Answered by CreepySkeleton
HerbM asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, the documentation for the macro is terrible. We would very much appreciate any help there!

You can call any method from Arg via method(arg) syntax.

clap_app!(myapp =>
    (@arg PORT: -p --port ... +takes_value default_value("22") "Port to test") 
)  

Playground

And you don't need any special support from clap for OS-specific config:

#[cfg(windows)]
const PORT: &str = "135";
#[cfg(not(windows))]
const PORT: &str = "22";

clap_app!(myapp =>
    (@arg PORT: -p --port ... +takes_value default_value(PORT) "Port to test") 
)  

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@HerbM
Comment options

Answer selected by HerbM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants