ommui_data 0.39.0

OMMUI data structures
Documentation
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 {
    /// Set the product id to something other than the default ("ommui").
    #[structopt(long = "productid", default_value = "ommui")]
    pub product_id: String,
    /// Set the company id to something other than the default ("ommui").
    #[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 {
    /// Check the device tree.
    #[structopt(name = "check")]
    Check(check::Arguments),
    /// Dump the data to stdout.
    #[structopt(name = "dump")]
    Dump(DumpArguments),
    /// Create the documentation tree.
    #[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(())
    }
}