Add runtime module

This commit is contained in:
Matthias Beyer 2015-10-18 20:52:52 +02:00
parent 8d4a1fa45e
commit bd6df27aec
2 changed files with 47 additions and 0 deletions

View file

@ -1,11 +1,16 @@
#[macro_use] extern crate clap; #[macro_use] extern crate clap;
use cli::Config; use cli::Config;
use runtime::Runtime;
mod cli; mod cli;
mod runtime;
fn main() { fn main() {
let mut config = Config::new(); let mut config = Config::new();
cli::configure(&mut config); cli::configure(&mut config);
let rt = Runtime::new(config);
println!("Hello, world!"); println!("Hello, world!");
} }

42
src/runtime.rs Normal file
View file

@ -0,0 +1,42 @@
use cli::Config;
use std::io::stderr;
use std::io::Write;
pub struct Runtime {
config : Config,
}
impl Runtime {
pub fn new(config : Config) -> Runtime {
Runtime {
config: config,
}
}
pub fn debug(&self, string : String) {
if self.config.is_debugging() {
println!("{}", string);
}
}
pub fn print(&self, string : String) {
if self.config.is_verbose() || self.config.is_debugging() {
println!("{}", string);
}
}
pub fn trace(string : String) {
// writeln!(&mut stderr, "{}", string);
}
pub fn is_verbose(&self) -> bool {
self.config.is_verbose()
}
pub fn is_debugging(&self) -> bool {
self.config.is_debugging()
}
}