1
0

feat: improve wfassoc-exec

This commit is contained in:
2026-04-21 16:30:25 +08:00
parent 3e588f0ac9
commit fc2097560c
4 changed files with 164 additions and 102 deletions

View File

@@ -1,45 +1,98 @@
use crate::cli::Request;
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)]
#[error("{0}")]
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),
}
/// Result type used in this module.
type Result<T> = std::result::Result<T, Error>;
// region: Respective Runners
// endregion
fn run_register() -> Result<()> {
// region: Utilities Functions
fn stringified_exts_to_indices(program: &wfassoc::Program, exts: Vec<String>) -> Result<Vec<usize>> {
todo!()
}
fn run_unregister() -> Result<()> {
todo!()
}
fn run_status() -> Result<()> {
todo!()
}
fn run_ext_link() -> Result<()> {
todo!()
}
fn run_ext_unlink() -> Result<()> {
todo!()
}
fn run_ext_list() -> Result<()> {
todo!()
}
// endregion
pub fn run(request: Request) -> Result<()> {
// region: Respective Runners
fn run_register(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> {
todo!()
}
fn run_unregister(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> {
todo!()
}
fn run_status(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> {
todo!()
}
fn run_ext_link(program: wfassoc::Program, scope: wfassoc::Scope, exts: Vec<String>) -> Result<()> {
let exts = stringified_exts_to_indices(&program, exts)?;
todo!()
}
fn run_ext_unlink(
program: wfassoc::Program,
scope: wfassoc::Scope,
exts: Vec<String>,
) -> 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)
}
},
}
}