mirror of
https://github.com/nushell/nushell
synced 2024-11-15 17:27:58 +00:00
feat: Use Raw Text to save if pipeline data is ExternalStream (#7082)
if not value type or Value as String in nushell, save will use raw type
This commit is contained in:
parent
d9d6cea5a9
commit
899383c30c
2 changed files with 24 additions and 0 deletions
|
@ -121,6 +121,11 @@ impl Command for Save {
|
|||
|
||||
let ext = if raw {
|
||||
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 {
|
||||
path.extension()
|
||||
.map(|name| name.to_string_lossy().to_string())
|
||||
|
|
|
@ -130,3 +130,22 @@ fn save_stderr_and_stdout_to_diff_file() {
|
|||
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>"#
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue