cat command to support multiple files #62

This commit is contained in:
sagie gur ari 2020-01-17 11:36:51 +00:00
parent 99b18562ca
commit b36050fbb2
4 changed files with 23 additions and 11 deletions

View file

@ -7,6 +7,7 @@
* New properties read/write commands #61
* Default command run implementation should crash and not error #63
* \[Breaking Change\] Invoking a command that does not exist should crash and not error
* cat command to support multiple files #62
### v0.1.6 (2020-01-12)

View file

@ -1,13 +1,13 @@
```sh
var = cat file
var = cat [file]+
```
The cat command will print out the requested file.<br>
The cat command will print out the requested file/s.<br>
In addition it will also return the value to the output variable.
#### Parameters
A single parameter holding the file path.
Multiple file paths.
#### Return Value

View file

@ -26,16 +26,18 @@ impl Command for CommandImpl {
if arguments.is_empty() {
CommandResult::Error("File name not provided.".to_string())
} else {
let result = io::read_text_file(&arguments[0]);
let mut all_text = String::new();
for argument in &arguments {
let result = io::read_text_file(&argument);
match result {
Ok(text) => {
println!("{}", &text);
CommandResult::Continue(Some(text))
match result {
Ok(text) => all_text.push_str(&text),
Err(error) => return CommandResult::Error(error.to_string()),
}
Err(error) => CommandResult::Error(error.to_string()),
}
println!("{}", &all_text);
CommandResult::Continue(Some(all_text))
}
}
}

View file

@ -13,10 +13,19 @@ fn run_no_file_provided() {
}
#[test]
fn run_valid() {
fn run_single_file() {
test::run_script_and_validate(
vec![create("")],
"out = cat ./Cargo.toml",
CommandValidation::Contains("out".to_string(), "duckscript".to_string()),
);
}
#[test]
fn run_multiple_files() {
test::run_script_and_validate(
vec![create("")],
"out = cat ./Cargo.toml ./Cargo.toml",
CommandValidation::Contains("out".to_string(), "duckscript".to_string()),
);
}