use crate::{check, doc, error, Result};
use ommui_data::filesystem::DeviceBuilder;
use ommui_data::LoadableDevice;
use snafu::ResultExt;
use std::path::PathBuf;
use structopt::StructOpt;
#[structopt(name = "ometo")]
#[derive(StructOpt, Debug)]
pub struct Arguments {
#[structopt(long = "productid", default_value = "ommui")]
pub product_id: String,
#[structopt(long = "companyid", default_value = "ommui")]
pub company_id: String,
#[structopt(subcommand)]
command: Command,
}
impl Arguments {
pub fn run(&self) -> Result<()> {
self.command.run(&self.product_id, &self.company_id)
}
}
#[derive(StructOpt, Debug)]
pub enum Command {
#[structopt(name = "check")]
Check(check::Arguments),
#[structopt(name = "dump")]
Dump(DumpArguments),
#[structopt(name = "doc")]
Doc(doc::Arguments),
}
impl Command {
fn run(&self, product_id: &str, company_id: &str) -> Result<()> {
match self {
Command::Check(args) => args.run(product_id, company_id),
Command::Dump(args) => args.run(product_id, company_id),
Command::Doc(args) => args.run(product_id, company_id),
}
}
}
#[derive(StructOpt, Debug)]
pub struct DumpArguments {
#[structopt(parse(from_os_str), default_value = ".")]
pub path: PathBuf,
}
impl DumpArguments {
fn run(&self, product_id: &str, company_id: &str) -> Result<()> {
let builder = DeviceBuilder::new(product_id, company_id)
.base_system_path(&self.path)
.build()
.context(error::OmmuiData)?;
let device = builder.load_device().context(error::OmmuiData)?;
println!("{:#?}", device);
Ok(())
}
}