2026-04-21 16:30:25 +08:00
|
|
|
use crate::cli;
|
|
|
|
|
use crate::manifest;
|
|
|
|
|
use std::path::Path;
|
2026-01-04 14:05:34 +08:00
|
|
|
use thiserror::Error as TeError;
|
|
|
|
|
|
2026-04-21 16:30:25 +08:00
|
|
|
// region: Error Handling
|
|
|
|
|
|
2026-01-04 14:05:34 +08:00
|
|
|
/// Error occurs in this module.
|
|
|
|
|
#[derive(Debug, TeError)]
|
|
|
|
|
pub enum Error {
|
2026-04-22 14:53:22 +08:00
|
|
|
/// Error when parsing Manifest TOML file.
|
2026-04-21 16:30:25 +08:00
|
|
|
#[error("{0}")]
|
|
|
|
|
ParseManifest(#[from] manifest::ParseManifestError),
|
2026-04-22 14:53:22 +08:00
|
|
|
/// Error when parsing Manifest into Schema.
|
2026-04-21 16:30:25 +08:00
|
|
|
#[error("{0}")]
|
|
|
|
|
ParseSchema(#[from] manifest::ParseSchemaError),
|
2026-04-22 14:53:22 +08:00
|
|
|
/// Error when parsing Schema into Program.
|
2026-04-21 16:30:25 +08:00
|
|
|
#[error("{0}")]
|
|
|
|
|
ParseProgram(#[from] wfassoc::highlevel::ParseProgramError),
|
2026-04-22 14:53:22 +08:00
|
|
|
/// Error when operating Program.
|
|
|
|
|
#[error("{0}")]
|
|
|
|
|
Program(#[from] wfassoc::highlevel::ProgramError),
|
2026-01-04 14:05:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Result type used in this module.
|
|
|
|
|
type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
|
2026-04-21 16:30:25 +08:00
|
|
|
// endregion
|
2026-01-04 14:05:34 +08:00
|
|
|
|
2026-04-21 16:30:25 +08:00
|
|
|
// region: Utilities Functions
|
|
|
|
|
|
|
|
|
|
fn stringified_exts_to_indices(program: &wfassoc::Program, exts: Vec<String>) -> Result<Vec<usize>> {
|
2026-01-04 14:05:34 +08:00
|
|
|
todo!()
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 16:30:25 +08:00
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
// region: Respective Runners
|
|
|
|
|
|
2026-04-22 14:53:22 +08:00
|
|
|
fn run_register(mut program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> {
|
|
|
|
|
Ok(program.register(scope)?)
|
2026-01-04 14:05:34 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-22 14:53:22 +08:00
|
|
|
fn run_unregister(mut program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> {
|
|
|
|
|
Ok(program.unregister(scope)?)
|
2026-01-04 14:05:34 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-22 14:53:22 +08:00
|
|
|
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(())
|
2026-01-04 14:05:34 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 16:30:25 +08:00
|
|
|
fn run_ext_link(program: wfassoc::Program, scope: wfassoc::Scope, exts: Vec<String>) -> Result<()> {
|
|
|
|
|
let exts = stringified_exts_to_indices(&program, exts)?;
|
2026-04-29 13:11:12 +08:00
|
|
|
for index in exts {
|
|
|
|
|
program.link_ext(scope, index)?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
2026-01-04 14:05:34 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 16:30:25 +08:00
|
|
|
fn run_ext_unlink(
|
|
|
|
|
program: wfassoc::Program,
|
|
|
|
|
scope: wfassoc::Scope,
|
|
|
|
|
exts: Vec<String>,
|
|
|
|
|
) -> Result<()> {
|
|
|
|
|
let exts = stringified_exts_to_indices(&program, exts)?;
|
2026-04-29 13:11:12 +08:00
|
|
|
for index in exts {
|
|
|
|
|
program.link_ext(scope, index)?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
2026-01-04 14:05:34 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 16:30:25 +08:00
|
|
|
fn run_ext_list(
|
|
|
|
|
program: wfassoc::Program,
|
|
|
|
|
view: wfassoc::View,
|
|
|
|
|
style: cli::ExtListStyle,
|
|
|
|
|
) -> Result<()> {
|
|
|
|
|
todo!()
|
|
|
|
|
}
|
2026-01-04 14:05:34 +08:00
|
|
|
|
|
|
|
|
// endregion
|
|
|
|
|
|
2026-04-21 16:30:25 +08:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
2026-01-04 14:05:34 +08:00
|
|
|
}
|