2025-10-19 17:37:51 +08:00
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-17 14:19:26 +08:00
|
|
|
|
|
|
|
|
/// Simple program to manage Windows file associations
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
|
#[command(name = "Windows File Association Operator", version, about)]
|
|
|
|
|
pub struct Cli {
|
2025-10-19 17:37:51 +08:00
|
|
|
/// The TOML file representing the complete program
|
2025-10-17 14:19:26 +08:00
|
|
|
#[arg(
|
|
|
|
|
short = 'c',
|
|
|
|
|
long = "config",
|
|
|
|
|
value_name = "PROG_CONFIG",
|
|
|
|
|
required = true
|
|
|
|
|
)]
|
|
|
|
|
pub(crate) config_file: String,
|
|
|
|
|
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
pub(crate) command: Commands,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
|
pub enum Commands {
|
|
|
|
|
/// Register the program
|
|
|
|
|
#[command(name = "register")]
|
2025-10-19 17:37:51 +08:00
|
|
|
#[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,
|
|
|
|
|
},
|
2025-10-17 14:19:26 +08:00
|
|
|
/// Unregister the program
|
|
|
|
|
#[command(name = "unregister")]
|
2025-10-19 17:37:51 +08:00
|
|
|
#[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,
|
|
|
|
|
},
|
2025-10-17 14:19:26 +08:00
|
|
|
/// Query file associations
|
|
|
|
|
#[command(name = "query")]
|
2025-10-19 17:37:51 +08:00
|
|
|
#[command(about = "Query file extensions association infos according toh given manifest represented application.")]
|
2025-10-17 14:19:26 +08:00
|
|
|
Query,
|
|
|
|
|
}
|