diff --git a/client/examples/repl/command.rs b/client/examples/repl/command.rs index 8cb5574b2..a5f8df621 100644 --- a/client/examples/repl/command.rs +++ b/client/examples/repl/command.rs @@ -56,12 +56,8 @@ impl Command for InitCommand { "init".to_string() } - fn required_param_length(&self) -> usize { - 1 - } - - fn error_message(&self) -> String { - "requires one argument: ".to_string() + fn required_parameters(&self) -> Vec { + vec![""].iter().map(|s| s.to_string()).collect() } } @@ -90,12 +86,11 @@ impl Command for GenerateKeyCommand { "keygen".to_string() } - fn required_param_length(&self) -> usize { - 3 - } - - fn error_message(&self) -> String { - "requires three arguments: ".to_string() + fn required_parameters(&self) -> Vec { + vec!["", "", ""] + .iter() + .map(|s| s.to_string()) + .collect() } } @@ -123,12 +118,8 @@ impl Command for CheckVaultCommand { "checkvault".to_string() } - fn required_param_length(&self) -> usize { - 1 - } - - fn error_message(&self) -> String { - "requires one argument: ".to_string() + fn required_parameters(&self) -> Vec { + vec![""].iter().map(|s| s.to_string()).collect() } } @@ -160,12 +151,11 @@ impl Command for CheckRecordCommand { "checkrecord".to_string() } - fn required_param_length(&self) -> usize { - 2 - } - - fn error_message(&self) -> String { - "requires two arguments: ".to_string() + fn required_parameters(&self) -> Vec { + vec!["", ""] + .iter() + .map(|s| s.to_string()) + .collect() } } @@ -189,12 +179,11 @@ impl Command for BackupCommand { "backup".to_string() } - fn required_param_length(&self) -> usize { - 2 - } - - fn error_message(&self) -> String { - "requires two arguments: ".to_string() + fn required_parameters(&self) -> Vec { + vec!["", ""] + .iter() + .map(|s| s.to_string()) + .collect() } } @@ -218,12 +207,11 @@ impl Command for RestoreCommand { "restore".to_string() } - fn required_param_length(&self) -> usize { - 2 - } - - fn error_message(&self) -> String { - "requires two arguments: ".to_string() + fn required_parameters(&self) -> Vec { + vec!["", ""] + .iter() + .map(|s| s.to_string()) + .collect() } } @@ -253,12 +241,11 @@ impl Command for Slip10GenerateCommand { "slip10gen".to_string() } - fn required_param_length(&self) -> usize { - 2 - } - - fn error_message(&self) -> String { - "requires two arguments: ".to_string() + fn required_parameters(&self) -> Vec { + vec!["", ""] + .iter() + .map(|s| s.to_string()) + .collect() } } @@ -295,13 +282,17 @@ impl Command for Slip10DeriveCommand { "slip10derive".to_string() } - fn required_param_length(&self) -> usize { - 5 - } - - fn error_message(&self) -> String { - "requires two arguments: " - .to_string() + fn required_parameters(&self) -> Vec { + vec![ + "", + "", + "", + "", + "", + ] + .iter() + .map(|s| s.to_string()) + .collect() } } @@ -331,12 +322,11 @@ impl Command for Bip39GenerateCommand { "mnemonic".to_string() } - fn required_param_length(&self) -> usize { - 4 - } - - fn error_message(&self) -> String { - "requires four arguments: ".to_string() + fn required_parameters(&self) -> Vec { + vec!["", "", "", ""] + .iter() + .map(|s| s.to_string()) + .collect() } } @@ -366,13 +356,18 @@ impl Command for Bip39RestoreCommand { "bip39restore".to_string() } - fn required_param_length(&self) -> usize { - 4 - } - - fn error_message(&self) -> String { - "requires 3 arguments: " - .to_string() + fn required_parameters(&self) -> Vec { + vec![ + "", + "", + "", + "", + "", + "", + ] + .iter() + .map(|s| s.to_string()) + .collect() } } diff --git a/client/examples/repl/main.rs b/client/examples/repl/main.rs index c65a62f71..79abf6afb 100644 --- a/client/examples/repl/main.rs +++ b/client/examples/repl/main.rs @@ -69,7 +69,7 @@ pub trait Command { /// Validates the number of input tokens, otherwise displays the provided error message fn validate(&self, parameter: &Vec) -> Result<(), ReplError> { - if parameter.len().ne(&self.required_param_length()) { + if parameter.len().ne(&self.required_parameters().len()) { return Err(ReplError::Invalid(format!( "'{}' {}", self.name(), @@ -84,13 +84,23 @@ pub trait Command { fn name(&self) -> String; /// Returns the number of required parameters - fn required_param_length(&self) -> usize { + fn required_parameters(&self) -> Vec { Default::default() } /// Returns the error message for the command fn error_message(&self) -> String { - Default::default() + let plural = |a: usize| match a { + 1 => "", + _ => "s", + }; + let req = self.required_parameters(); + format!( + "requires {} argument{}: {}", + req.len(), + plural(req.len()), + req.join(" ") + ) } }