diff --git a/clap_builder/src/derive.rs b/clap_builder/src/derive.rs index 7494e8461dc4..079949188d70 100644 --- a/clap_builder/src/derive.rs +++ b/clap_builder/src/derive.rs @@ -62,6 +62,30 @@ pub trait Parser: FromArgMatches + CommandFactory + Sized { } } + /// Parse from a string, return Err on error. + fn try_parse_from_string(string: S) -> Result + where + S: AsRef, + { + let argv0 = std::iter::once(""); + let itr = string.as_ref().split_whitespace(); + let itr = argv0.chain(itr); + + Self::try_parse_from(itr) + } + + /// Parse from a string, exit on error. + fn parse_from_string(string: S) -> Self + where + S: AsRef, + { + let argv0 = std::iter::once(""); + let itr = string.as_ref().split_whitespace(); + let itr = argv0.chain(itr); + + Self::parse_from(itr) + } + /// Parse from iterator, return Err on error. fn try_parse_from(itr: I) -> Result where