Browse Source

Make commands case insensitive

checkpoints
Aditya Kulkarni 5 years ago
parent
commit
2cbdab37fa
  1. 31
      lib/src/commands.rs
  2. 2
      lib/src/lightclient.rs

31
lib/src/commands.rs

@ -757,8 +757,37 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
}
pub fn do_user_command(cmd: &str, args: &Vec<&str>, lightclient: &LightClient) -> String {
match get_commands().get(cmd) {
match get_commands().get(&cmd.to_ascii_lowercase()) {
Some(cmd) => cmd.exec(args, lightclient),
None => format!("Unknown command : {}. Type 'help' for a list of commands", cmd)
}
}
#[cfg(test)]
pub mod tests {
use lazy_static::lazy_static;
use super::do_user_command;
use crate::lightclient::{LightClient};
lazy_static!{
static ref TEST_SEED: String = "youth strong sweet gorilla hammer unhappy congress stamp left stereo riot salute road tag clean toilet artefact fork certain leopard entire civil degree wonder".to_string();
}
#[test]
pub fn test_command_caseinsensitive() {
let lc = LightClient::unconnected(TEST_SEED.to_string(), None).unwrap();
assert_eq!(do_user_command("addresses", &vec![], &lc),
do_user_command("AddReSSeS", &vec![], &lc));
assert_eq!(do_user_command("addresses", &vec![], &lc),
do_user_command("Addresses", &vec![], &lc));
}
#[test]
pub fn test_nosync_commands() {
// The following commands should run
}
}

2
lib/src/lightclient.rs

@ -244,7 +244,7 @@ impl LightClient {
/// Method to create a test-only version of the LightClient
#[allow(dead_code)]
fn unconnected(seed_phrase: String, dir: Option<String>) -> io::Result<Self> {
pub fn unconnected(seed_phrase: String, dir: Option<String>) -> io::Result<Self> {
let config = LightClientConfig::create_unconnected("test".to_string(), dir);
let mut l = LightClient {
wallet : Arc::new(RwLock::new(LightWallet::new(Some(seed_phrase), &config, 0)?)),

Loading…
Cancel
Save