1
0
mirror of https://github.com/nushell/nushell.git synced 2025-07-16 06:15:07 +02:00

feat: Use Raw Text to save if pipeline data is ExternalStream ()

if not value type or Value as String in nushell, save will use raw type
This commit is contained in:
Access
2022-11-21 09:32:15 +08:00
committed by GitHub
parent d9d6cea5a9
commit 899383c30c
2 changed files with 24 additions and 0 deletions
crates/nu-command
src
filesystem
tests
commands

@ -121,6 +121,11 @@ impl Command for Save {
let ext = if raw { let ext = if raw {
None None
// if is extern stream , in other words , not value
} else if let PipelineData::ExternalStream { .. } = input {
None
} else if let PipelineData::Value(Value::String { .. }, ..) = input {
None
} else { } else {
path.extension() path.extension()
.map(|name| name.to_string_lossy().to_string()) .map(|name| name.to_string_lossy().to_string())

@ -130,3 +130,22 @@ fn save_stderr_and_stdout_to_diff_file() {
assert!(!actual.contains("bar")); assert!(!actual.contains("bar"));
}) })
} }
#[test]
fn save_string_and_stream_as_raw() {
Playground::setup("save_test_7", |dirs, sandbox| {
sandbox.with_files(vec![]);
let expected_file = dirs.test().join("temp.html");
nu!(
cwd: dirs.root(),
r#"
`<!DOCTYPE html><html><body><a href='http://example.org/'>Example</a></body></html>` | save save_test_7/temp.html
"#,
);
let actual = file_contents(expected_file);
assert_eq!(
actual,
r#"<!DOCTYPE html><html><body><a href='http://example.org/'>Example</a></body></html>"#
)
})
}