write header/footer with fif version, sh shebang, etc.
This commit is contained in:
parent
00de841fda
commit
3963910e1e
1 changed files with 22 additions and 7 deletions
|
@ -1,14 +1,16 @@
|
|||
use std::io::{self, Write};
|
||||
use crate::Findings;
|
||||
use crate::scanerror::ScanError;
|
||||
use std::path::PathBuf;
|
||||
use snailquote::escape;
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use snailquote::escape;
|
||||
|
||||
use crate::Findings;
|
||||
use crate::scanerror::ScanError;
|
||||
|
||||
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
||||
|
||||
type Entries = [Result<Findings, (ScanError, PathBuf)>];
|
||||
|
||||
|
@ -32,9 +34,13 @@ pub trait Format {
|
|||
fn no_known_extension<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()>;
|
||||
fn unreadable<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()>;
|
||||
fn unknown_type<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()>;
|
||||
fn header<W: Write>(&self, entries: &Entries, f: &mut W) -> io::Result<()>;
|
||||
fn footer<W: Write>(&self, entries: &Entries, f: &mut W) -> io::Result<()>;
|
||||
|
||||
fn write_all<W: Write>(&self, entries: &Entries, f: &mut W) -> io::Result<()> {
|
||||
// TODO: clean this up - it's horrifying
|
||||
self.header(entries, f)?;
|
||||
|
||||
for entry in entries {
|
||||
match entry {
|
||||
Ok(finding) => {
|
||||
|
@ -64,7 +70,8 @@ pub trait Format {
|
|||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
self.footer(entries, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,4 +108,12 @@ impl Format for Script {
|
|||
write_pathbuf(f, path)?;
|
||||
write!(f, "\n")
|
||||
}
|
||||
|
||||
fn header<W: Write>(&self, _: &Entries, f: &mut W) -> io::Result<()> {
|
||||
write!(f, "#!/usr/bin/env sh\n\nGenerated by fif {}.\n\n", VERSION.unwrap_or("???"))
|
||||
}
|
||||
|
||||
fn footer<W: Write>(&self, _: &Entries, f: &mut W) -> io::Result<()> {
|
||||
writeln!(f, "\necho Done.")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue