1
0
Files
wfassoc/wfassoc-exec/src/runner.rs

99 lines
2.7 KiB
Rust
Raw Normal View History

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-21 16:30:25 +08:00
/// 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),
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
fn run_register(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> {
2026-01-04 14:05:34 +08:00
todo!()
}
2026-04-21 16:30:25 +08:00
fn run_unregister(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> {
2026-01-04 14:05:34 +08:00
todo!()
}
2026-04-21 16:30:25 +08:00
fn run_status(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> {
2026-01-04 14:05:34 +08:00
todo!()
}
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-01-04 14:05:34 +08:00
todo!()
}
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-01-04 14:05:34 +08:00
todo!()
}
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
}