Add db output for testing
This commit is contained in:
parent
408757149c
commit
185f7ced8d
@ -2,6 +2,7 @@ use log::warn;
|
|||||||
use serde_json;
|
use serde_json;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::fmt;
|
||||||
use std::path;
|
use std::path;
|
||||||
|
|
||||||
extern crate custom_error;
|
extern crate custom_error;
|
||||||
@ -31,6 +32,36 @@ pub struct Database {
|
|||||||
contents: Vec<Category>,
|
contents: Vec<Category>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Group {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
writeln!(f, " ({})", self.name)?;
|
||||||
|
for file in self.files.iter() {
|
||||||
|
writeln!(f, r#" File "{}": {}"#, file.name, file.contents.to_string())?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Category {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
writeln!(f, "[{}]", self.name)?;
|
||||||
|
for g in self.groups.iter() {
|
||||||
|
write!(f, "{}", g)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Database {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
writeln!(f, "DB: {}", self.storage.display())?;
|
||||||
|
for c in self.contents.iter() {
|
||||||
|
writeln!(f, "{}", c)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub fn new(storage: &path::Path) -> Result<Database, Box<dyn Error>> {
|
pub fn new(storage: &path::Path) -> Result<Database, Box<dyn Error>> {
|
||||||
if !storage.is_dir() {
|
if !storage.is_dir() {
|
||||||
|
@ -7,7 +7,7 @@ fn main() {
|
|||||||
let filename = &args[1];
|
let filename = &args[1];
|
||||||
let config = database::Database::new(Path::new(filename));
|
let config = database::Database::new(Path::new(filename));
|
||||||
match config {
|
match config {
|
||||||
Ok(db) => print!("ok"),
|
Ok(db) => print!("{}", db),
|
||||||
_ => (),
|
Err(error) => println!("OH NO: {}", error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user