mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
save --append: create file if it doesn't exist (#4156)
* have save --append create file if not exists Currently, doing: echo a | save --raw --append file.txt will fail if file.txt does not exist. This PR changes that * test that `save --append` will create new file
This commit is contained in:
parent
91c270c14a
commit
fb197f562a
@ -47,3 +47,21 @@ fn writes_out_csv() {
|
||||
assert!(actual.contains("nu,0.14,A new type of shell,MIT,2018"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_append_will_create_file_if_not_exists() {
|
||||
Playground::setup("save_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![]);
|
||||
|
||||
let expected_file = dirs.test().join("new-file.txt");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.root(),
|
||||
r#"echo hello | save --raw --append save_test_3/new-file.txt"#,
|
||||
);
|
||||
|
||||
let actual = file_contents(expected_file);
|
||||
println!("{}", actual);
|
||||
assert!(actual == "hello");
|
||||
})
|
||||
}
|
||||
|
@ -884,7 +884,7 @@ impl Shell for FilesystemShell {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let mut options = OpenOptions::new();
|
||||
if append {
|
||||
options.append(true)
|
||||
options.append(true).create(true)
|
||||
} else {
|
||||
options.write(true).create(true).truncate(true)
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user