Use is_amount clap validator (#7400)

* Fix up is_amount to handle floats for SOL; expand amount_of test

* Use required_lamports_from and is_amount across CLI

* Remove obsolete test (now handled by clap)
This commit is contained in:
Tyera Eulberg
2019-12-10 11:29:17 -07:00
committed by GitHub
parent 6f457292ff
commit 11521dca08
6 changed files with 49 additions and 23 deletions

View File

@ -120,8 +120,12 @@ pub fn is_valid_percentage(percentage: String) -> Result<(), String> {
}
pub fn is_amount(amount: String) -> Result<(), String> {
amount
.parse::<u64>()
.map(|_| ())
.map_err(|e| format!("{:?}", e))
if amount.parse::<u64>().is_ok() || amount.parse::<f64>().is_ok() {
Ok(())
} else {
Err(format!(
"Unable to parse input amount as integer or float, provided: {}",
amount
))
}
}