Auto merge of #40 - matthiasbeyer:cleanup, r=matthiasbeyer

Cleanup

Codebase cleanup
This commit is contained in:
Homu 2016-01-02 07:51:58 +09:00
commit bbcf0e2dba
16 changed files with 30 additions and 87 deletions

View file

@ -9,8 +9,6 @@
extern crate url; extern crate url;
extern crate config; extern crate config;
use std::process::exit;
pub use cli::CliConfig; pub use cli::CliConfig;
pub use configuration::Configuration; pub use configuration::Configuration;
pub use runtime::{ImagLogger, Runtime}; pub use runtime::{ImagLogger, Runtime};
@ -32,10 +30,9 @@ fn main() {
let app = App::from_yaml(yaml); let app = App::from_yaml(yaml);
let config = CliConfig::new(app); let config = CliConfig::new(app);
let configuration = Configuration::new(&config); let configuration = Configuration::new(&config);
ImagLogger::init(&configuration, &config);
let logger = ImagLogger::init(&configuration, &config);
debug!("Logger created!"); debug!("Logger created!");
debug!("CliConfig : {:?}", &config); debug!("CliConfig : {:?}", &config);
debug!("Configuration: {:?}", &configuration); debug!("Configuration: {:?}", &configuration);
@ -49,6 +46,4 @@ fn main() {
} else { } else {
info!("No commandline call...") info!("No commandline call...")
} }
info!("Hello, world!");
} }

View file

@ -1,20 +1,13 @@
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use std::cell::RefCell;
use std::fmt; use std::fmt;
use std::ops::Deref; use std::ops::Deref;
use std::process::exit; use std::process::exit;
use clap::ArgMatches; use clap::ArgMatches;
use regex::Regex;
use runtime::Runtime; use runtime::Runtime;
use module::Module; use module::Module;
use storage::Store;
use storage::file::hash::FileHash;
use storage::file::id::FileID;
use storage::file::File;
use storage::parser::FileHeaderParser; use storage::parser::FileHeaderParser;
use storage::parser::Parser; use storage::parser::Parser;
use storage::json::parser::JsonHeaderParser; use storage::json::parser::JsonHeaderParser;
@ -38,10 +31,6 @@ impl<'a> BM<'a> {
} }
} }
fn runtime(&self) -> &Runtime {
&self.rt
}
/** /**
* Subcommand: add * Subcommand: add
*/ */
@ -142,8 +131,6 @@ impl<'a> BM<'a> {
* Subcommand: remove * Subcommand: remove
*/ */
fn command_remove(&self, matches: &ArgMatches) -> bool { fn command_remove(&self, matches: &ArgMatches) -> bool {
use std::process::exit;
let parser = Parser::new(JsonHeaderParser::new(None)); let parser = Parser::new(JsonHeaderParser::new(None));
let filter : Box<CliFileFilter> = get_file_filter_by_cli(&parser, matches, "id", "match", "tags", None); let filter : Box<CliFileFilter> = get_file_filter_by_cli(&parser, matches, "id", "match", "tags", None);
let result = self.rt let result = self.rt
@ -307,7 +294,7 @@ impl<'a> Module<'a> for BM<'a> {
impl<'a> Debug for BM<'a> { impl<'a> Debug for BM<'a> {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "BM"); try!(write!(fmt, "BM"));
Ok(()) Ok(())
} }

View file

@ -8,8 +8,6 @@ use regex::Regex;
use storage::file::File; use storage::file::File;
use storage::file::hash::FileHash; use storage::file::hash::FileHash;
use storage::file::header::data::FileHeaderData;
use storage::file::id::FileID;
use storage::json::parser::JsonHeaderParser; use storage::json::parser::JsonHeaderParser;
use storage::parser::FileHeaderParser; use storage::parser::FileHeaderParser;
use storage::parser::Parser; use storage::parser::Parser;

View file

@ -3,7 +3,6 @@
*/ */
pub mod cli { pub mod cli {
use clap::ArgMatches; use clap::ArgMatches;
use regex::Regex;
use runtime::Runtime; use runtime::Runtime;

View file

@ -1,13 +1,7 @@
use std::collections::HashMap; use std::fmt::Debug;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::fmt::Result as FMTResult;
use std::result::Result;
use clap::ArgMatches; use clap::ArgMatches;
use runtime::Runtime;
pub mod bm; pub mod bm;
pub mod helpers; pub mod helpers;

View file

@ -1,6 +1,5 @@
use std::convert::{From, Into}; use std::convert::{From, Into};
use std::error::Error; use std::fmt::{Display, Formatter};
use std::fmt::{Debug, Display, Formatter};
use std::fmt; use std::fmt;
use std::hash::Hash; use std::hash::Hash;
use uuid::Uuid; use uuid::Uuid;

View file

@ -47,7 +47,7 @@ impl<'a> Error for MatchError<'a> {
impl<'a> Debug for MatchError<'a> { impl<'a> Debug for MatchError<'a> {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "{}", self.format()); try!(write!(fmt, "{}", self.format()));
Ok(()) Ok(())
} }
@ -56,7 +56,7 @@ impl<'a> Debug for MatchError<'a> {
impl<'a> Display for MatchError<'a> { impl<'a> Display for MatchError<'a> {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "{}", self.format()); try!(write!(fmt, "{}", self.format()));
Ok(()) Ok(())
} }

View file

@ -1,4 +1,4 @@
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Display, Formatter};
use std::fmt; use std::fmt;
#[derive(Debug)] #[derive(Debug)]

View file

@ -1,9 +1,6 @@
use std::convert::{From, Into}; use std::convert::{From, Into};
use std::error::Error;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use std::fmt; use std::fmt;
use std::hash::Hash;
use std::path::PathBuf;
use std::result::Result; use std::result::Result;
use std::str::FromStr; use std::str::FromStr;
@ -100,9 +97,9 @@ impl FileID {
impl Debug for FileID { impl Debug for FileID {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "FileID[{:?}]: {:?}", try!(write!(fmt, "FileID[{:?}]: {:?}",
self.id_type, self.id_type,
self.id); self.id));
Ok(()) Ok(())
} }
@ -111,9 +108,9 @@ impl Debug for FileID {
impl Display for FileID { impl Display for FileID {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "FileID[{:?}]: {:?}", try!(write!(fmt, "FileID[{:?}]: {:?}",
self.id_type, self.id_type,
self.id); self.id));
Ok(()) Ok(())
} }

View file

@ -1,7 +1,5 @@
use std::convert::{From, Into}; use std::convert::{From, Into};
use std::error::Error;
use std::str::FromStr; use std::str::FromStr;
use std::hash::Hash;
#[derive(Debug)] #[derive(Debug)]
#[derive(Clone)] #[derive(Clone)]

View file

@ -1,4 +1,3 @@
use std::error::Error;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use std::fmt; use std::fmt;
@ -9,14 +8,7 @@ pub mod id_type;
pub mod header; pub mod header;
pub mod hash; pub mod hash;
use module::Module;
use storage::file::id::*; use storage::file::id::*;
use storage::file::id_type::FileIDType;
use storage::file::hash::FileHash;
use super::parser::{FileHeaderParser, Parser, ParserError};
use self::header::spec::*;
use self::header::data::*; use self::header::data::*;
/** /**
@ -93,7 +85,7 @@ impl File {
impl Display for File { impl Display for File {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, try!(write!(fmt,
"[File] Owner : '{:?}' "[File] Owner : '{:?}'
FileID: '{:?}' FileID: '{:?}'
Header: '{:?}' Header: '{:?}'
@ -101,7 +93,7 @@ impl Display for File {
self.owning_module_name, self.owning_module_name,
self.header, self.header,
self.data, self.data,
self.id); self.id));
Ok(()) Ok(())
} }
@ -110,7 +102,7 @@ impl Display for File {
impl Debug for File { impl Debug for File {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, try!(write!(fmt,
"[File] Owner : '{:?}' "[File] Owner : '{:?}'
FileID: '{:?}' FileID: '{:?}'
Header: '{:?}' Header: '{:?}'
@ -118,7 +110,7 @@ impl Debug for File {
self.owning_module_name, self.owning_module_name,
self.id, self.id,
self.header, self.header,
self.data); self.data));
Ok(()) Ok(())
} }

View file

@ -30,7 +30,7 @@ impl JsonHeaderParser {
impl Display for JsonHeaderParser { impl Display for JsonHeaderParser {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "JsonHeaderParser"); try!(write!(fmt, "JsonHeaderParser"));
Ok(()) Ok(())
} }
@ -39,7 +39,7 @@ impl Display for JsonHeaderParser {
impl Debug for JsonHeaderParser { impl Debug for JsonHeaderParser {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "JsonHeaderParser, Spec: {:?}", self.spec); try!(write!(fmt, "JsonHeaderParser, Spec: {:?}", self.spec));
Ok(()) Ok(())
} }

View file

@ -12,12 +12,11 @@ pub mod parser;
pub mod json; pub mod json;
use module::Module; use module::Module;
use runtime::Runtime;
use storage::file::File; use storage::file::File;
use storage::file::id::FileID; use storage::file::id::FileID;
use storage::file::id_type::FileIDType; use storage::file::id_type::FileIDType;
use storage::file::hash::FileHash; use storage::file::hash::FileHash;
use storage::parser::{FileHeaderParser, Parser, ParserError}; use storage::parser::{FileHeaderParser, Parser};
use storage::file::header::data::FileHeaderData; use storage::file::header::data::FileHeaderData;
type Cache = HashMap<FileID, Rc<RefCell<File>>>; type Cache = HashMap<FileID, Rc<RefCell<File>>>;
@ -266,7 +265,7 @@ impl Store {
}) })
} }
use glob::{glob, Paths, PatternError}; use glob::glob;
let hashstr : String = hash.into(); let hashstr : String = hash.into();
let globstr = format!("{}/*-{}.imag", self.storepath, hashstr); let globstr = format!("{}/*-{}.imag", self.storepath, hashstr);
@ -301,7 +300,7 @@ impl Store {
-> Vec<Rc<RefCell<File>>> -> Vec<Rc<RefCell<File>>>
where HP: FileHeaderParser where HP: FileHeaderParser
{ {
use glob::{glob, Paths, PatternError}; use glob::glob;
let globstr = format!("{}/{}-*.imag", self.storepath, m.name()); let globstr = format!("{}/{}-*.imag", self.storepath, m.name());
let mut res = vec![]; let mut res = vec![];

View file

@ -57,13 +57,13 @@ impl Error for ParserError {
impl Debug for ParserError { impl Debug for ParserError {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "ParserError: {}\n\n", self.summary); try!(write!(fmt, "ParserError: {}\n\n", self.summary));
if let Some(ref e) = self.explanation { if let Some(ref e) = self.explanation {
write!(fmt, "{}\n\n", e); try!(write!(fmt, "{}\n\n", e));
} }
write!(fmt, "On position {}\nin\n{}", self.index, self.parsertext); try!(write!(fmt, "On position {}\nin\n{}", self.index, self.parsertext));
Ok(()) Ok(())
} }
@ -72,10 +72,10 @@ impl Debug for ParserError {
impl Display for ParserError { impl Display for ParserError {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "ParserError: {}", self.summary); try!(write!(fmt, "ParserError: {}", self.summary));
if let Some(ref e) = self.explanation { if let Some(ref e) = self.explanation {
write!(fmt, "\n\n{}", e); try!(write!(fmt, "\n\n{}", e));
} }
Ok(()) Ok(())
@ -196,8 +196,7 @@ impl<HP> Debug for Parser<HP>
{ {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "Parser<{:?}>", self.headerp); try!(write!(fmt, "Parser<{:?}>", self.headerp));
Ok(()) Ok(())
} }

View file

@ -1,12 +1,3 @@
use std::ops::Drop;
use std::path::PathBuf;
use std::fs::File;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::fmt;
use runtime::Runtime; use runtime::Runtime;
/** /**
@ -17,7 +8,6 @@ pub fn let_user_provide_content(rt: &Runtime) -> Option<String> {
use std::io::Read; use std::io::Read;
use std::fs::File; use std::fs::File;
use std::process::Command; use std::process::Command;
use std::process::Child;
let filepath = "/tmp/imag-tmp.md"; let filepath = "/tmp/imag-tmp.md";
let file_created = File::create(filepath) let file_created = File::create(filepath)

View file

@ -120,8 +120,6 @@ impl FilePrinter for SimplePrinter {
* Table printer to print file information in a nice ASCII-table * Table printer to print file information in a nice ASCII-table
*/ */
pub struct TablePrinter { pub struct TablePrinter {
verbose: bool,
debug: bool,
sp: SimplePrinter, sp: SimplePrinter,
} }
@ -129,8 +127,6 @@ impl FilePrinter for TablePrinter {
fn new(verbose: bool, debug: bool) -> TablePrinter { fn new(verbose: bool, debug: bool) -> TablePrinter {
TablePrinter { TablePrinter {
debug: debug,
verbose: verbose,
sp: SimplePrinter::new(verbose, debug), sp: SimplePrinter::new(verbose, debug),
} }
} }