mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
cat command to support multiple files #62
This commit is contained in:
parent
99b18562ca
commit
b36050fbb2
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
Ok(text) => all_text.push_str(&text),
|
||||
Err(error) => return CommandResult::Error(error.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
CommandResult::Continue(Some(text))
|
||||
}
|
||||
Err(error) => CommandResult::Error(error.to_string()),
|
||||
}
|
||||
println!("{}", &all_text);
|
||||
CommandResult::Continue(Some(all_text))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue