Rename parse to from_str

This commit is contained in:
David Peter 2022-02-20 13:19:23 +01:00 committed by David Peter
parent 0ebd76dfc2
commit f9e62e5e7f

View File

@ -44,7 +44,7 @@ impl fmt::Display for Shell {
impl Shell { impl Shell {
/// Parse given string as shell command line /// Parse given string as shell command line
pub fn parse<'a>(s: &str) -> Result<Self, OptionsError<'a>> { pub fn from_str<'a>(s: &str) -> Result<Self, OptionsError<'a>> {
let v = shell_words::split(s).map_err(OptionsError::ShellParseError)?; let v = shell_words::split(s).map_err(OptionsError::ShellParseError)?;
if v.is_empty() || v[0].is_empty() { if v.is_empty() || v[0].is_empty() {
return Err(OptionsError::EmptyShell); return Err(OptionsError::EmptyShell);
@ -138,7 +138,7 @@ pub struct Options {
/// Whether or not to ignore non-zero exit codes /// Whether or not to ignore non-zero exit codes
pub command_failure_action: CmdFailureAction, pub command_failure_action: CmdFailureAction,
/// Command to run before each timing run /// Command(s) to run before each timing run
pub preparation_command: Option<Vec<String>>, pub preparation_command: Option<Vec<String>>,
/// Command to run before each *batch* of timing runs, i.e. before each individual benchmark /// Command to run before each *batch* of timing runs, i.e. before each individual benchmark
@ -268,7 +268,7 @@ impl Options {
}; };
if let Some(shell) = matches.value_of("shell") { if let Some(shell) = matches.value_of("shell") {
options.shell = Shell::parse(shell)?; options.shell = Shell::from_str(shell)?;
} }
if matches.is_present("ignore-failure") { if matches.is_present("ignore-failure") {
@ -313,8 +313,8 @@ fn test_shell_default_command() {
} }
#[test] #[test]
fn test_shell_parse_command() { fn test_can_parse_shell_command_line_from_str() {
let shell = Shell::parse("shell -x 'aaa bbb'").unwrap(); let shell = Shell::from_str("shell -x 'aaa bbb'").unwrap();
let s = format!("{}", shell); let s = format!("{}", shell);
assert_eq!(&s, "shell -x 'aaa bbb'"); assert_eq!(&s, "shell -x 'aaa bbb'");
@ -330,17 +330,17 @@ fn test_shell_parse_command() {
// Error cases // Error cases
assert!(matches!( assert!(matches!(
Shell::parse("shell 'foo").unwrap_err(), Shell::from_str("shell 'foo").unwrap_err(),
OptionsError::ShellParseError(_) OptionsError::ShellParseError(_)
)); ));
assert!(matches!( assert!(matches!(
Shell::parse("").unwrap_err(), Shell::from_str("").unwrap_err(),
OptionsError::EmptyShell OptionsError::EmptyShell
)); ));
assert!(matches!( assert!(matches!(
Shell::parse("''").unwrap_err(), Shell::from_str("''").unwrap_err(),
OptionsError::EmptyShell OptionsError::EmptyShell
)); ));
} }