Add file printer helpers

This commit is contained in:
Matthias Beyer 2015-11-30 18:41:42 +01:00
parent 78aeddb42e
commit 918016368e
3 changed files with 73 additions and 0 deletions

View file

@ -17,6 +17,7 @@ mod configuration;
mod runtime;
mod module;
mod storage;
mod ui;
fn main() {
let yaml = load_yaml!("../etc/cli.yml");

71
src/ui/file.rs Normal file
View file

@ -0,0 +1,71 @@
use std::iter::Iterator;
use runtime::Runtime;
use storage::file::File;
pub trait FilePrinter {
fn new(verbose: bool, debug: bool) -> Self;
/*
* Print a single file
*/
fn print_file(&self, &File);
/*
* Print a list of files
*/
fn print_files<'a, I: Iterator<Item = File<'a>>>(&self, files: I) {
for file in files {
self.print_file(&file);
}
}
}
struct DebugPrinter {
debug: bool,
}
impl FilePrinter for DebugPrinter {
fn new(verbose: bool, debug: bool) -> DebugPrinter {
DebugPrinter {
debug: debug,
}
}
fn print_file(&self, f: &File) {
if self.debug {
debug!("[DebugPrinter] ->\n{:?}", f);
}
}
}
struct SimplePrinter {
verbose: bool,
debug: bool,
}
impl FilePrinter for SimplePrinter {
fn new(verbose: bool, debug: bool) -> SimplePrinter {
SimplePrinter {
debug: debug,
verbose: verbose,
}
}
fn print_file(&self, f: &File) {
if self.debug {
debug!("{:?}", f);
} else if self.verbose {
info!("{}", f);
} else {
info!("[File]: {}", f.id());
}
}
}

1
src/ui/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod file;