difftreelog
fix do not write trailing newline in --multi for -S
in: master
2 files changed
cmds/jrsonnet/src/main.rsdiffbeforeafterboth200 }200 }201 println!("{}", path.to_str().expect("path"));201 println!("{}", path.to_str().expect("path"));202 let mut file = File::create(path)?;202 let mut file = File::create(path)?;203 writeln!(203 write!(204 file,204 file,205 "{}",205 "{}",206 data.manifest(&manifest_format)206 data.manifest(&manifest_format)207 .with_description(|| format!("manifesting {field}"))?207 .with_description(|| format!("manifesting {field}"))?,208 )?;208 )?;209 if manifest_format.file_trailing_newline() {210 writeln!(file)?;211 }212 file.flush()?;209 }213 }210 } else if let Some(path) = opts.output.output_file {214 } else if let Some(path) = opts.output.output_file {211 if opts.output.create_output_dirs {215 if opts.output.create_output_dirs {crates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/manifest.rs
@@ -12,6 +12,13 @@
self.manifest_buf(val, &mut out)?;
Ok(out)
}
+ /// When outputing to file, is it safe to append a trailing newline (I.e newline won't change
+ /// the meaning).
+ ///
+ /// Default implementation returns `true`
+ fn file_trailing_newline(&self) -> bool {
+ true
+ }
}
impl<T> ManifestFormat for Box<T>
where
@@ -21,6 +28,10 @@
let inner = &**self;
inner.manifest_buf(val, buf)
}
+ fn file_trailing_newline(&self) -> bool {
+ let inner = &**self;
+ inner.file_trailing_newline()
+ }
}
impl<T> ManifestFormat for &'_ T
where
@@ -30,6 +41,10 @@
let inner = &**self;
inner.manifest_buf(val, buf)
}
+ fn file_trailing_newline(&self) -> bool {
+ let inner = &**self;
+ inner.file_trailing_newline()
+ }
}
#[derive(PartialEq, Eq, Clone, Copy)]
@@ -253,6 +268,9 @@
fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {
JsonFormat::std_to_string().manifest_buf(val, out)
}
+ fn file_trailing_newline(&self) -> bool {
+ false
+ }
}
pub struct StringFormat;
impl ManifestFormat for StringFormat {
@@ -263,6 +281,9 @@
write!(out, "{s}").unwrap();
Ok(())
}
+ fn file_trailing_newline(&self) -> bool {
+ false
+ }
}
pub struct YamlStreamFormat<I>(pub I);