Clap 3 Beta: Add default values using @args macro #2034
-
[Rust & clap newbie using clap 3.x beta to parse args] Problem and goal is to add defaults to @arg within the myapp .I am using
It may be the case that I've chosen badly by using the @arg macro instead of one of the other (more flexible?) clap choices. As a side note, is there a method to use any of the other styles with the macro style for clap or do I just rewrite it to use features not (easily) supported by the macro style? Also, it would be nice to make the default OS specific, "Unixy" vs. Windows. The docs don't seem to have an example for any clap shortcuts for doing either of these, but they do suggest both are possible. Thanks for any help. I read a lot of the docs, searched the examples directory, and Google a bunch of articles. Probably because 3.x is in Beta. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, the documentation for the macro is terrible. We would very much appreciate any help there! You can call any method from clap_app!(myapp =>
(@arg PORT: -p --port ... +takes_value default_value("22") "Port to test")
) 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")
) |
Beta Was this translation helpful? Give feedback.
Yes, the documentation for the macro is terrible. We would very much appreciate any help there!
You can call any method from
Arg
viamethod(arg)
syntax.Playground
And you don't need any special support from clap for OS-specific config: