1
0

feat: upgrade wfassoc_exec

This commit is contained in:
2025-12-30 23:21:01 +08:00
parent 7a03d38f68
commit 27ab6721de
13 changed files with 331 additions and 182 deletions

View File

@@ -1,48 +1,39 @@
use clap::{Parser, Subcommand, ValueEnum};
use wfassoc::Scope;
#[derive(Debug, Clone, ValueEnum)]
pub enum Target {
// region: Clap Declaration
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ValueEnum)]
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 representing the complete program
struct Cli {
/// The TOML manifest file representing the complete program
#[arg(
short = 'c',
long = "config",
value_name = "PROG_CONFIG",
short = 'm',
long = "manifest",
value_name = "PROG_MANIFEST",
required = true
)]
pub(crate) config_file: String,
manifest_file: String,
#[command(subcommand)]
pub(crate) command: Commands,
command: CliCommands,
}
#[derive(Subcommand)]
pub enum Commands {
enum CliCommands {
/// Register the program
#[command(name = "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)]
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = Target::User)]
target: Target,
},
/// Unregister the program
@@ -50,11 +41,76 @@ pub enum Commands {
#[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)]
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, 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,
/// Fetch current registration status
#[command(name = "status")]
#[command(
about = "Fetch the status of registration for given manifest represented application."
)]
Status,
#[command(name = "ext")]
#[command(about = "File extension related operations according to given program manifest.")]
Ext {
#[command(subcommand)]
command: CliExtCommands,
},
}
#[derive(Subcommand)]
enum CliExtCommands {
#[command(name = "link")]
#[command(about = "Link user given file extension to the program declared in manifest file.")]
Link {
// The file extensions used for this operation. Specify * for all file extension.
#[arg(required = true, value_name = "EXTS", num_args = 1..)]
exts: Vec<String>,
},
#[command(name = "unlink")]
#[command(
about = "Unlink user given file extension from the program declared in manifest file."
)]
Unlink {
// The file extensions used for this operation. Specify * for all file extension.
#[arg(required = true, value_name = "EXTS", num_args = 1..)]
exts: Vec<String>,
},
#[command(name = "list")]
#[command(
about = "List the association status for all extensions declared in given program manifest."
)]
List,
}
// endregion
// region: Exposed Type
#[derive(Debug)]
pub struct Request {
}
#[derive(Debug)]
pub struct RequestCommand {
}
#[derive(Debug)]
pub struct RequestExtCommand {
}
// endregion
///
///
/// Please note that if there is "help" or "version" command matched,
/// or any command line parse error occurs,
/// this function will order program exit immediately.
/// This is the mechanism of clap crate.
pub fn parse() -> Request {
let cli = Cli::parse();
}