difftreelog
fix do not write trailing newline in --multi for -S
in: master
2 files changed
cmds/jrsonnet/src/main.rsdiffbeforeafterboth--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -200,12 +200,16 @@
}
println!("{}", path.to_str().expect("path"));
let mut file = File::create(path)?;
- writeln!(
+ write!(
file,
"{}",
data.manifest(&manifest_format)
- .with_description(|| format!("manifesting {field}"))?
+ .with_description(|| format!("manifesting {field}"))?,
)?;
+ if manifest_format.file_trailing_newline() {
+ writeln!(file)?;
+ }
+ file.flush()?;
}
} else if let Some(path) = opts.output.output_file {
if opts.output.create_output_dirs {
crates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth12 self.manifest_buf(val, &mut out)?;12 self.manifest_buf(val, &mut out)?;13 Ok(out)13 Ok(out)14 }14 }15 /// When outputing to file, is it safe to append a trailing newline (I.e newline won't change16 /// the meaning).17 ///18 /// Default implementation returns `true`19 fn file_trailing_newline(&self) -> bool {20 true21 }15}22}16impl<T> ManifestFormat for Box<T>23impl<T> ManifestFormat for Box<T>17where24where21 let inner = &**self;28 let inner = &**self;22 inner.manifest_buf(val, buf)29 inner.manifest_buf(val, buf)23 }30 }31 fn file_trailing_newline(&self) -> bool {32 let inner = &**self;33 inner.file_trailing_newline()34 }24}35}25impl<T> ManifestFormat for &'_ T36impl<T> ManifestFormat for &'_ T26where37where30 let inner = &**self;41 let inner = &**self;31 inner.manifest_buf(val, buf)42 inner.manifest_buf(val, buf)32 }43 }44 fn file_trailing_newline(&self) -> bool {45 let inner = &**self;46 inner.file_trailing_newline()47 }33}48}344935#[derive(PartialEq, Eq, Clone, Copy)]50#[derive(PartialEq, Eq, Clone, Copy)]253 fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {268 fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {254 JsonFormat::std_to_string().manifest_buf(val, out)269 JsonFormat::std_to_string().manifest_buf(val, out)255 }270 }271 fn file_trailing_newline(&self) -> bool {272 false273 }256}274}257pub struct StringFormat;275pub struct StringFormat;258impl ManifestFormat for StringFormat {276impl ManifestFormat for StringFormat {263 write!(out, "{s}").unwrap();281 write!(out, "{s}").unwrap();264 Ok(())282 Ok(())265 }283 }284 fn file_trailing_newline(&self) -> bool {285 false286 }266}287}267288268pub struct YamlStreamFormat<I>(pub I);289pub struct YamlStreamFormat<I>(pub I);