diff --git a/wfassoc-exec/src/cli.rs b/wfassoc-exec/src/cli.rs index 2b54e95..d260bc8 100644 --- a/wfassoc-exec/src/cli.rs +++ b/wfassoc-exec/src/cli.rs @@ -82,9 +82,9 @@ pub enum CliCommands { #[command(name = "status")] #[command(about = "Fetch the status of registration with given manifest and scope.")] Status { - /// The scope where fetch info. - #[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = RegScope::User)] - target: RegScope, + /// The view where fetch info. + #[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = RegView::User)] + target: RegView, }, #[command(name = "ext")] #[command(about = "File extension related operations according to given program manifest.")] diff --git a/wfassoc-exec/src/runner.rs b/wfassoc-exec/src/runner.rs index 6272506..a6fe8ae 100644 --- a/wfassoc-exec/src/runner.rs +++ b/wfassoc-exec/src/runner.rs @@ -8,15 +8,18 @@ use thiserror::Error as TeError; /// Error occurs in this module. #[derive(Debug, TeError)] pub enum Error { - /// Error when parsing manifest TOML file. + /// Error when parsing Manifest TOML file. #[error("{0}")] ParseManifest(#[from] manifest::ParseManifestError), - /// Error when parsing manifest into schema. + /// Error when parsing Manifest into Schema. #[error("{0}")] ParseSchema(#[from] manifest::ParseSchemaError), - /// Error when parsing schema into program. + /// 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. @@ -34,16 +37,22 @@ fn stringified_exts_to_indices(program: &wfassoc::Program, exts: Vec) -> // region: Respective Runners -fn run_register(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> { - todo!() +fn run_register(mut program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> { + Ok(program.register(scope)?) } -fn run_unregister(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> { - todo!() +fn run_unregister(mut program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> { + Ok(program.unregister(scope)?) } -fn run_status(program: wfassoc::Program, scope: wfassoc::Scope) -> Result<()> { - todo!() +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<()> { diff --git a/wfassoc/src/highlevel.rs b/wfassoc/src/highlevel.rs index 6df9bc9..eee0f43 100644 --- a/wfassoc/src/highlevel.rs +++ b/wfassoc/src/highlevel.rs @@ -167,17 +167,43 @@ pub struct Program { impl TryFrom for Program { type Error = ParseProgramError; - fn try_from(value: Schema) -> std::result::Result { + fn try_from(value: Schema) -> Result { Self::new(value) } } impl Program { + /// Try creating Program from Schema. pub fn new(schema: Schema) -> Result { todo!() } } +impl Program { + /// Register this application. + /// + /// If there is registration of this application, + /// this function will return error. + pub fn register(&mut self, scope: Scope) -> Result<(), ProgramError> { + todo!() + } + + /// Unregister this application. + /// + /// If there is no registration of this application, + /// this function will return error. + pub fn unregister(&mut self, scope: Scope) -> Result<(), ProgramError> { + todo!() + } + + /// Check whether this application has been registered in given view. + /// + /// Please note that this is a rough check and do not validate any data. + pub fn is_registered(&self, view: View) -> Result { + todo!() + } +} + // endregion // region: Program Internals