feat: update wfassoc-exec
This commit is contained in:
@@ -3,10 +3,45 @@ use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use thiserror::Error as TeError;
|
||||
use toml;
|
||||
use wfassoc;
|
||||
|
||||
/// Error occurs in this module.
|
||||
// region: Manifest
|
||||
|
||||
/// Raw user input manifest.
|
||||
///
|
||||
/// This manifest is the raw input of user.
|
||||
/// Some fields may not be checked due to user invalid input.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Manifest {
|
||||
identifier: String,
|
||||
path: String,
|
||||
clsid: String,
|
||||
|
||||
name: Option<String>,
|
||||
icon: Option<String>,
|
||||
behavior: Option<String>,
|
||||
|
||||
strs: HashMap<String, String>,
|
||||
icons: HashMap<String, String>,
|
||||
behaviors: HashMap<String, String>,
|
||||
exts: HashMap<String, ManifestExt>,
|
||||
}
|
||||
|
||||
/// The sub-type in raw user input manifest.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ManifestExt {
|
||||
name: String,
|
||||
icon: String,
|
||||
behavior: String,
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region: Manifest Operation
|
||||
|
||||
/// Error occurs when parsing manifest TOML file.
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum Error {
|
||||
pub enum ParseManifestError {
|
||||
/// Io error
|
||||
#[error("IO error when reading manifest file")]
|
||||
Io(#[from] std::io::Error),
|
||||
@@ -15,77 +50,27 @@ pub enum Error {
|
||||
Toml(#[from] toml::de::Error),
|
||||
}
|
||||
|
||||
/// Result type used in this module.
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
// region: Raw Manifest
|
||||
|
||||
/// Raw user input manifest.
|
||||
///
|
||||
/// This manifest is the raw input of user.
|
||||
/// Some fields may not be checked due to user invalid input.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct RawManifest {
|
||||
identifier: String,
|
||||
path: String,
|
||||
clsid: String,
|
||||
icons: HashMap<String, String>,
|
||||
behaviors: HashMap<String, String>,
|
||||
exts: HashMap<String, RawManifestExt>,
|
||||
}
|
||||
|
||||
impl RawManifest {
|
||||
pub fn into_checked(&self) -> Result<Manifest> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// The sub-type in raw user input manifest.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct RawManifestExt {
|
||||
name: String,
|
||||
icon: String,
|
||||
behavior: String,
|
||||
}
|
||||
|
||||
impl RawManifestExt {
|
||||
pub fn into_checked(&self) -> Result<ManifestExt> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl RawManifest {
|
||||
/// Read raw user manifest.
|
||||
pub fn from_file(path: &Path) -> Result<RawManifest> {
|
||||
impl Manifest {
|
||||
/// Read user manifest.
|
||||
pub fn from_file(path: &Path) -> Result<Manifest, ParseManifestError> {
|
||||
let contents = std::fs::read_to_string(path)?;
|
||||
let config: RawManifest = toml::from_str(&contents)?;
|
||||
let config: Manifest = toml::from_str(&contents)?;
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region: Checked Manifest
|
||||
|
||||
/// Converted user input manifest.
|
||||
///
|
||||
/// This manifest struct is prepared for final use.
|
||||
/// All fields loacted in this struct is checked and ready to be used.
|
||||
#[derive(Debug)]
|
||||
pub struct Manifest {
|
||||
|
||||
/// Error occurs when parsing manifest into schema.
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum ParseSchemaError {
|
||||
|
||||
}
|
||||
|
||||
impl Manifest {
|
||||
|
||||
}
|
||||
|
||||
pub struct ManifestExt {
|
||||
|
||||
}
|
||||
|
||||
impl ManifestExt {
|
||||
impl TryFrom<Manifest> for wfassoc::Schema {
|
||||
type Error = ParseSchemaError;
|
||||
|
||||
fn try_from(value: Manifest) -> std::result::Result<Self, Self::Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
Reference in New Issue
Block a user