feat: trim cmd args in parser (#3789)

This commit is contained in:
Panagiotis Ganelis
2023-07-15 13:33:33 +03:00
committed by GitHub
parent 300b496686
commit be656c239a
2 changed files with 20 additions and 1 deletions

View File

@ -526,6 +526,25 @@ mod tests {
);
}
#[test]
fn test_transport_rpc_module_trim_config() {
let args = CommandParser::<RpcServerArgs>::parse_from([
"reth",
"--http.api",
" eth, admin, debug",
"--http",
"--ws",
])
.args;
let config = args.transport_rpc_module_config();
let expected = vec![RethRpcModule::Eth, RethRpcModule::Admin, RethRpcModule::Debug];
assert_eq!(config.http().cloned().unwrap().into_selection(), expected);
assert_eq!(
config.ws().cloned().unwrap().into_selection(),
RpcModuleSelection::standard_modules()
);
}
#[test]
fn test_rpc_server_config() {
let args = CommandParser::<RpcServerArgs>::parse_from([

View File

@ -604,7 +604,7 @@ impl FromStr for RpcModuleSelection {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut modules = s.split(',').peekable();
let mut modules = s.split(',').map(str::trim).peekable();
let first = modules.peek().copied().ok_or(ParseError::VariantNotFound)?;
match first {
"all" | "All" => Ok(RpcModuleSelection::All),