use crate::cli; use crate::manifest; use std::path::Path; use thiserror::Error as TeError; // region: Error Handling /// Error occurs in this module. #[derive(Debug, TeError)] pub enum Error { /// Error when parsing Manifest TOML file. #[error("{0}")] ParseManifest(#[from] manifest::ParseManifestError), /// Error when parsing Manifest into Schema. #[error("{0}")] ParseSchema(#[from] manifest::ParseSchemaError), /// Error when parsing Schema into Program. #[error("{0}")] ParseProgram(#[from] wfassoc::highlevel::ParseProgramError), /// Error when operating Program. #[error("{0}")] Program(#[from] wfassoc::highlevel::ProgramError), } /// Result type used in this module. type Result = std::result::Result; // endregion // region: Utilities Functions fn stringified_exts_to_indices(program: &wfassoc::Program, exts: Vec) -> Result> { todo!() } // endregion // region: Respective Runners fn run_register(mut program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> { Ok(program.register(scope)?) } fn run_unregister(mut program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> { Ok(program.unregister(scope)?) } fn run_status(program: wfassoc::Program, view: wfassoc::View) -> Result<()> { if program.is_registered(view)? { println!("Application is installed."); } else { println!("Application is not installed."); } Ok(()) } fn run_ext_link(program: wfassoc::Program, scope: wfassoc::Scope, exts: Vec) -> Result<()> { let exts = stringified_exts_to_indices(&program, exts)?; todo!() } fn run_ext_unlink( program: wfassoc::Program, scope: wfassoc::Scope, exts: Vec, ) -> Result<()> { let exts = stringified_exts_to_indices(&program, exts)?; todo!() } fn run_ext_list( program: wfassoc::Program, view: wfassoc::View, style: cli::ExtListStyle, ) -> Result<()> { todo!() } // endregion pub fn run(c: cli::Cli) -> Result<()> { // Read manifest file first let mf = manifest::Manifest::from_file(Path::new(&c.manifest_file))?; println!("{:?}", mf); // Parse it into schema let schema = mf.into_schema()?; // Parse it into program let program = schema.into_program()?; match c.command { cli::CliCommands::Register { target } => run_register(program, target.into()), cli::CliCommands::Unregister { target } => run_unregister(program, target.into()), cli::CliCommands::Status { target } => run_status(program, target.into()), cli::CliCommands::Ext { command } => match command { cli::CliExtCommands::Link { target, exts } => { run_ext_link(program, target.into(), exts) } cli::CliExtCommands::Unlink { target, exts } => { run_ext_unlink(program, target.into(), exts) } cli::CliExtCommands::List { target, style } => { run_ext_list(program, target.into(), style) } }, } }