mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-26 02:11:56 +00:00
un-workspace
This commit is contained in:
33
src/command_helpers.rs
Normal file
33
src/command_helpers.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use std::fmt::Display;
|
||||
use std::io::Stdin;
|
||||
use std::str::FromStr;
|
||||
|
||||
use clap::ArgMatches;
|
||||
pub use {clap, serde};
|
||||
|
||||
pub fn default_arg_parser<T>(arg: &str, _: &ArgMatches) -> Result<T, clap::Error>
|
||||
where
|
||||
T: FromStr,
|
||||
T::Err: Display,
|
||||
{
|
||||
arg.parse()
|
||||
.map_err(|e| clap::Error::raw(clap::error::ErrorKind::ValueValidation, e))
|
||||
}
|
||||
|
||||
pub fn default_stdin_parser<T>(stdin: &mut Stdin, _: &ArgMatches) -> Result<T, clap::Error>
|
||||
where
|
||||
T: FromStr,
|
||||
T::Err: Display,
|
||||
{
|
||||
let mut s = String::new();
|
||||
stdin
|
||||
.read_line(&mut s)
|
||||
.map_err(|e| clap::Error::raw(clap::error::ErrorKind::Io, e))?;
|
||||
if let Some(s) = s.strip_suffix("\n") {
|
||||
s
|
||||
} else {
|
||||
&s
|
||||
}
|
||||
.parse()
|
||||
.map_err(|e| clap::Error::raw(clap::error::ErrorKind::ValueValidation, e))
|
||||
}
|
||||
Reference in New Issue
Block a user