From ccb6dfc38ee147fc87f2e2390a5fb5764b9066b0 Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Tue, 17 Jan 2023 18:34:22 +0100 Subject: [PATCH] refactoring: rename variable 'command' to 'keyword' --- src/execute.rs | 4 ++-- src/parse.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/execute.rs b/src/execute.rs index 4cd84ba..43bd632 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -20,8 +20,8 @@ pub fn execute>(mut command: Command, stdin: S) -> io::Result<(Ch } pub fn interpret(line: &str) -> io::Result<()> { - let (command, args) = parse_line(line); - let mut command = Command::new(command); + let (keyword, args) = parse_line(line); + let mut command = Command::new(keyword); command.args(args); let (mut stdout, _) = execute(command, Stdio::null())?; io::copy(&mut stdout, &mut io::stdout())?; diff --git a/src/parse.rs b/src/parse.rs index 4d07452..c194120 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,14 +1,14 @@ pub fn parse_line(line: &str) -> (&str, Vec<&str>) { let tokens = tokenize(line); - let command = tokens[0]; + let keyword = tokens[0]; let mut args: Vec<&str> = Vec::new(); if tokens.len() > 1 { args = tokens[1..].to_vec(); } - (command, args) + (keyword, args) } fn tokenize(line: &str) -> Vec<&str> { @@ -22,16 +22,16 @@ mod tests { #[test] fn test_tokenize() { assert_eq!( - tokenize("test arg1 arg2 arg3"), - vec!["test", "arg1", "arg2", "arg3"] + tokenize("keyword arg1 arg2 arg3"), + vec!["keyword", "arg1", "arg2", "arg3"] ); } #[test] fn test_parse_line() { assert_eq!( - parse_line("test arg1 arg2 arg3"), - ("test", vec!["arg1", "arg2", "arg3"]) + parse_line("keyword arg1 arg2 arg3"), + ("keyword", vec!["arg1", "arg2", "arg3"]) ); } }