1
0

feat(cli): implement register and unregister commands with scope support

- Add Target enum to handle user/system scope selection
- Move scope argument from global CLI to register/unregister subcommands
- Implement actual registration logic including ProgId subkey creation
- Update Program::new to accept string path instead of Path
- Add proper error handling and success messages
This commit is contained in:
2025-10-19 17:37:51 +08:00
parent f42c50ce10
commit d493285900
3 changed files with 93 additions and 48 deletions

View File

@@ -1,10 +1,28 @@
use clap::{Parser, Subcommand};
use clap::{Parser, Subcommand, ValueEnum};
use wfassoc::Scope;
#[derive(Debug, Clone, ValueEnum)]
pub enum Target {
#[value(name = "user")]
User,
#[value(name = "system")]
System,
}
impl From<Target> for Scope {
fn from(target: Target) -> Self {
match target {
Target::User => Scope::User,
Target::System => Scope::System,
}
}
}
/// Simple program to manage Windows file associations
#[derive(Parser)]
#[command(name = "Windows File Association Operator", version, about)]
pub struct Cli {
/// The toml file introducing the complete program
/// The TOML file representing the complete program
#[arg(
short = 'c',
long = "config",
@@ -13,40 +31,30 @@ pub struct Cli {
)]
pub(crate) config_file: String,
/// The scope where wfassoc operate
#[arg(short = 'f', long = "for", value_name = "TARGET", value_enum, default_value_t = ForTarget::User)]
pub(crate) for_which: ForTarget,
#[command(subcommand)]
pub(crate) command: Commands,
}
#[derive(clap::ValueEnum, Clone)]
pub enum ForTarget {
#[value(name = "user")]
User,
#[value(name = "system")]
System,
}
// impl From<ForTarget> for RegisterKind {
// fn from(target: ForTarget) -> Self {
// match target {
// ForTarget::User => RegisterKind::User,
// ForTarget::System => RegisterKind::System,
// }
// }
// }
#[derive(Subcommand)]
pub enum Commands {
/// Register the program
#[command(name = "register")]
Register,
#[command(about = "Register application with given manifest and scope.")]
Register {
/// The scope where wfassoc operate
#[arg(short = 't', long = "target", value_name = "TARGET", value_enum, default_value_t = Target::User)]
target: Target,
},
/// Unregister the program
#[command(name = "unregister")]
Unregister,
#[command(about = "Unregister application with given manifest and scope.")]
Unregister {
/// The scope where wfassoc operate
#[arg(short = 't', long = "target", value_name = "TARGET", value_enum, default_value_t = Target::User)]
target: Target,
},
/// Query file associations
#[command(name = "query")]
#[command(about = "Query file extensions association infos according toh given manifest represented application.")]
Query,
}