2015-10-18 13:58:17 +00:00
|
|
|
#[macro_use] extern crate clap;
|
2015-10-26 19:53:12 +00:00
|
|
|
#[macro_use] extern crate log;
|
2015-11-09 17:33:44 +00:00
|
|
|
#[macro_use] extern crate serde;
|
2015-11-08 16:32:43 +00:00
|
|
|
#[macro_use] extern crate serde_json;
|
2015-11-20 14:33:40 +00:00
|
|
|
#[macro_use] extern crate glob;
|
2015-11-23 17:58:25 +00:00
|
|
|
#[macro_use] extern crate uuid;
|
2015-10-25 18:56:04 +00:00
|
|
|
#[macro_use] extern crate regex;
|
2015-11-30 18:05:29 +00:00
|
|
|
#[macro_use] extern crate prettytable;
|
2015-12-04 14:09:03 +00:00
|
|
|
extern crate url;
|
2015-10-26 22:51:44 +00:00
|
|
|
extern crate config;
|
2015-10-18 13:58:17 +00:00
|
|
|
|
2015-12-05 00:14:13 +00:00
|
|
|
use std::process::exit;
|
|
|
|
|
2015-10-26 23:02:42 +00:00
|
|
|
use cli::CliConfig;
|
2015-10-26 22:51:44 +00:00
|
|
|
use configuration::Configuration;
|
2015-10-26 19:53:12 +00:00
|
|
|
use runtime::{ImagLogger, Runtime};
|
2015-10-25 18:47:17 +00:00
|
|
|
use clap::App;
|
2015-10-25 18:56:04 +00:00
|
|
|
use module::Module;
|
|
|
|
use module::ModuleError;
|
2015-11-28 10:55:40 +00:00
|
|
|
use module::CommandEnv;
|
2015-10-25 18:56:04 +00:00
|
|
|
use module::bm::BMModule;
|
2015-11-28 10:43:30 +00:00
|
|
|
use storage::backend::StorageBackend;
|
2015-10-18 13:58:17 +00:00
|
|
|
|
|
|
|
mod cli;
|
2015-10-26 22:51:44 +00:00
|
|
|
mod configuration;
|
2015-10-18 18:52:52 +00:00
|
|
|
mod runtime;
|
2015-10-24 15:46:01 +00:00
|
|
|
mod module;
|
2015-10-18 19:59:17 +00:00
|
|
|
mod storage;
|
2015-11-30 17:41:42 +00:00
|
|
|
mod ui;
|
2015-10-18 13:58:17 +00:00
|
|
|
|
|
|
|
fn main() {
|
2015-10-25 18:47:17 +00:00
|
|
|
let yaml = load_yaml!("../etc/cli.yml");
|
|
|
|
let app = App::from_yaml(yaml);
|
2015-11-27 15:49:25 +00:00
|
|
|
let config = CliConfig::new(app);
|
2015-10-26 21:30:15 +00:00
|
|
|
let configuration = Configuration::new(&config);
|
2015-10-18 18:52:52 +00:00
|
|
|
|
2015-10-26 22:59:24 +00:00
|
|
|
let logger = ImagLogger::init(&configuration, &config);
|
2015-10-26 20:26:55 +00:00
|
|
|
debug!("Logger created!");
|
|
|
|
|
2015-11-27 18:24:58 +00:00
|
|
|
debug!("CliConfig : {:?}", &config);
|
|
|
|
debug!("Configuration: {:?}", &configuration);
|
|
|
|
|
2015-10-26 23:01:11 +00:00
|
|
|
let rt = Runtime::new(configuration, config);
|
2015-11-27 18:24:58 +00:00
|
|
|
|
|
|
|
debug!("Runtime : {:?}", &rt);
|
2015-10-18 18:52:52 +00:00
|
|
|
|
2015-12-01 16:31:41 +00:00
|
|
|
let backend = StorageBackend::new(&rt).unwrap_or_else(|e| {
|
|
|
|
error!("Error: {}", e);
|
|
|
|
exit(1);
|
|
|
|
});
|
|
|
|
|
2015-10-25 18:56:04 +00:00
|
|
|
if let Some(matches) = rt.config.cli_matches.subcommand_matches("bm") {
|
2015-11-28 11:35:49 +00:00
|
|
|
let module = BMModule::new(&rt);
|
2015-11-28 10:36:06 +00:00
|
|
|
let commands = module.get_commands(&rt);
|
|
|
|
if let Some(command) = matches.subcommand_name() {
|
|
|
|
debug!("Subcommand: {}", command);
|
2015-11-28 10:43:30 +00:00
|
|
|
|
2015-11-28 10:55:40 +00:00
|
|
|
let cmdenv = CommandEnv {
|
|
|
|
rt: &rt,
|
|
|
|
bk: &backend,
|
2015-11-28 11:08:20 +00:00
|
|
|
matches: matches.subcommand_matches(command).unwrap(),
|
2015-11-28 10:55:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let result = match commands.get(command) {
|
2015-11-28 11:35:49 +00:00
|
|
|
Some(f) => f(&module, cmdenv),
|
2015-11-28 10:55:40 +00:00
|
|
|
None => Err(ModuleError::new("No subcommand found")),
|
|
|
|
};
|
|
|
|
|
|
|
|
debug!("Result of command: {:?}", result);
|
2015-11-28 10:36:06 +00:00
|
|
|
} else {
|
|
|
|
debug!("No subcommand");
|
|
|
|
}
|
|
|
|
|
2015-10-25 18:56:04 +00:00
|
|
|
module.shutdown(&rt);
|
|
|
|
} else {
|
|
|
|
// Err(ModuleError::mk("No commandline call"))
|
|
|
|
info!("No commandline call...")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-26 19:55:31 +00:00
|
|
|
info!("Hello, world!");
|
2015-10-18 13:58:17 +00:00
|
|
|
}
|