Skip to content

Commit

Permalink
feat(derive): parse from string and try parse from string
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-ardi committed Oct 23, 2023
1 parent 1b84314 commit 64433c8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions clap_builder/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ pub trait Parser: FromArgMatches + CommandFactory + Sized {
}
}

/// Parse from a string, return Err on error.
fn try_parse_from_string<S>(string: S) -> Result<Self, Error>
where
S: AsRef<str>,
{
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<S>(string: S) -> Self
where
S: AsRef<str>,
{
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<I, T>(itr: I) -> Result<Self, Error>
where
Expand Down

0 comments on commit 64433c8

Please sign in to comment.