Skip to content

Commit

Permalink
common arg parser helper for u32
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Jun 28, 2023
1 parent b6e26dd commit f7ba6a6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libs/marinade-common-cli/src/matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use solana_clap_utils::keypair::signer_from_path;
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signer::Signer;
use std::num::ParseIntError;
use std::{str::FromStr, sync::Arc};

// Getting signer from the matched name as the keypair path argument, or returns the default signer
Expand Down Expand Up @@ -88,3 +89,10 @@ fn pubkey_or_from_path(
Ok(signer.pubkey())
}
}

pub fn parse_u32(matches: &ArgMatches<'_>, name: &str) -> anyhow::Result<u32> {
let value = matches
.value_of(name)
.ok_or_else(|| anyhow::Error::msg(format!("argument '{}' missing", name)))?;
u32::from_str(value).map_err(|err: ParseIntError| anyhow::Error::msg(err))
}

0 comments on commit f7ba6a6

Please sign in to comment.