Replies: 1 comment 2 replies
-
What if we add a trait: trait ArgHint {
// Reasonable default value_name for Self
//
// By convention, this should be SCREAMING_CASE
//
// When `None`, clap will provide a value name based on the argument name
fn value_name() -> Option<&str> {
None
}
fn value_hint() -> Option<ValueHInt> {
None
}
}
impl ArgHint for i32 {
fn value_name() -> Option<&str> {
Some("NUM")
}
}
// ditto for other numbers
impl ArgHint for std::path::PathBuf {
fn value_name() -> Option<&str> {
Some("PATH")
}
fn value_hint() -> Option<ValueHInt> {
Some(ValueHint::AnyPath)
}
} By being a trait,
The downside is everything must implement it. We could probably use the tricks in #2298 or similar to work around this. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Right now, we only use types to infer occurrences / values (see #1772) or some limited capabilities when a user sets
arg_enum
.What else can we infer from types?
Path
, set ValueHint::AnyPathvalue_name
based on the type, likeNUM
for integers,PATH
forPath
, etcPath
,OsString
, etc.FromStr
,TryFrom<&OsStr>
, etc., in clap_derive #2298 wuld help with thisBeta Was this translation helpful? Give feedback.
All reactions