Commit f0c888f1 authored by Alexis Janon's avatar Alexis Janon
Browse files

Show module integration

parent ed87d125
......@@ -2,17 +2,20 @@ pub mod sysfscontroller;
use self::sysfscontroller::{get_sys_fs_controllers, SysFsControllerList};
use error::*;
use serde_json;
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
pub struct Configuration {
controllers: SysFsControllerList,
pub struct SysConf {
pub controllers: SysFsControllerList,
}
// TODO: use the same controller as in main?
pub fn get_configuration() -> Result<String> {
let conf = Configuration {
controllers: get_sys_fs_controllers()?,
};
serde_json::to_string(&conf).map_err(Error::from)
pub fn get_configuration() -> Result<SysConf> {
Ok(SysConf {
controllers: get_sys_fs_controllers().map_err(|err| {
Error::from(format!(
"Could not retrieve controllers: {}",
err.to_string()
))
})?,
})
}
......@@ -15,3 +15,4 @@ pub mod configuration;
pub mod error;
pub mod parsing;
pub mod result;
pub mod show;
......@@ -4,7 +4,7 @@ extern crate clap;
extern crate cuttr;
extern crate log4rs;
use clap::{App, Arg, SubCommand};
use clap::{App, Arg, ArgMatches, SubCommand};
use cuttr::configuration::sysfscontroller::{get_sys_fs_controllers, SysFsControllerList};
use cuttr::error::*;
use cuttr::result::*;
......@@ -58,11 +58,15 @@ fn exec() -> Result<CommandResult> {
).subcommand(
SubCommand::with_name("show")
.about("Shows information about the system")
.arg(
Arg::with_name("TYPE")
.help("The information type requested")
.possible_values(&["configuration"])
.required(true),
.subcommand(SubCommand::with_name("configuration").help("Show configuration"))
.subcommand(
SubCommand::with_name("slice")
.help("Show key/value pairs of a given slice")
.arg(
Arg::with_name("JSON")
.help("JSON slice and key/value list")
.required(true),
),
),
).get_matches();
let level = match LOG_DEFAULT + matches.occurrences_of("v") as i64
......@@ -84,7 +88,7 @@ fn exec() -> Result<CommandResult> {
})?);
match matches.subcommand() {
("transaction", Some(sub_m)) => transaction(sub_m.value_of("JSON").unwrap(), controllers),
("show", Some(sub_m)) => show(sub_m.value_of("TYPE").unwrap()),
("show", Some(sub_m)) => show(sub_m),
(name, _) => Err(Error::from(format!("Unknown subcommand: {}", name))),
}
}
......@@ -104,19 +108,29 @@ fn transaction(json: &str, controllers: Rc<SysFsControllerList>) -> Result<Comma
}
}
fn show(info_type: &str) -> Result<CommandResult> {
match info_type {
"configuration" => {
let configuration = configuration::get_configuration().map_err(|err| {
fn show(matches: &ArgMatches) -> Result<CommandResult> {
match matches.subcommand() {
("configuration", _) => {
let configuration = show::configuration().map_err(|err| {
Error::from(format!(
"Could not retrieve configuration: {}",
"Could not get serialized configuration: {}",
err.to_string()
))
})?;
println!("{}", configuration);
Ok(CommandResult::from(()))
}
_ => Err(Error::from(format!("Unknown info type: {}", info_type))),
("slice", Some(sub_m)) => {
let slice_info = show::slice(sub_m.value_of("JSON").unwrap()).map_err(|err| {
Error::from(format!(
"Could not get serialized slice information: {}",
err.to_string()
))
})?;
println!("{}", slice_info);
Ok(CommandResult::from(()))
}
(name, _) => Err(Error::from(format!("Unknown show subcommand: {}", name))),
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment