feat: improve wfassoc-exec
This commit is contained in:
@@ -3,53 +3,89 @@ use clap::{Parser, Subcommand, ValueEnum};
|
||||
// region: Clap Declaration
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ValueEnum)]
|
||||
enum Target {
|
||||
pub enum RegScope {
|
||||
#[value(name = "user")]
|
||||
User,
|
||||
#[value(name = "system")]
|
||||
System,
|
||||
}
|
||||
|
||||
impl From<RegScope> for wfassoc::Scope {
|
||||
fn from(value: RegScope) -> Self {
|
||||
match value {
|
||||
RegScope::User => wfassoc::Scope::User,
|
||||
RegScope::System => wfassoc::Scope::System,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ValueEnum)]
|
||||
pub enum RegView {
|
||||
#[value(name = "user")]
|
||||
User,
|
||||
#[value(name = "system")]
|
||||
System,
|
||||
#[value(name = "hybrid")]
|
||||
Hybrid,
|
||||
}
|
||||
|
||||
impl From<RegView> for wfassoc::View {
|
||||
fn from(value: RegView) -> Self {
|
||||
match value {
|
||||
RegView::User => wfassoc::View::User,
|
||||
RegView::System => wfassoc::View::System,
|
||||
RegView::Hybrid => wfassoc::View::Hybrid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ValueEnum)]
|
||||
pub enum ExtListStyle {
|
||||
#[value(name = "human")]
|
||||
Human,
|
||||
#[value(name = "machine")]
|
||||
Machine,
|
||||
}
|
||||
|
||||
/// Simple program to manage Windows file associations
|
||||
#[derive(Parser)]
|
||||
#[command(name = "Windows File Association Operator", version, about)]
|
||||
struct Cli {
|
||||
pub struct Cli {
|
||||
/// The TOML manifest file representing the complete program
|
||||
#[arg(
|
||||
short = 'm',
|
||||
long = "manifest",
|
||||
value_name = "PROG_MANIFEST",
|
||||
value_name = "MANIFEST_TOML",
|
||||
required = true
|
||||
)]
|
||||
manifest_file: String,
|
||||
pub manifest_file: String,
|
||||
#[command(subcommand)]
|
||||
command: CliCommands,
|
||||
pub command: CliCommands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum CliCommands {
|
||||
/// Register the program
|
||||
pub enum CliCommands {
|
||||
#[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", required = true, value_enum, default_value_t = Target::User)]
|
||||
target: Target,
|
||||
/// The scope where wfassoc operate.
|
||||
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = RegScope::User)]
|
||||
target: RegScope,
|
||||
},
|
||||
/// Unregister the program
|
||||
#[command(name = "unregister")]
|
||||
#[command(about = "Unregister application with given manifest and scope.")]
|
||||
Unregister {
|
||||
/// The scope where wfassoc operate
|
||||
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = Target::User)]
|
||||
target: Target,
|
||||
/// The scope where wfassoc operate.
|
||||
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = RegScope::User)]
|
||||
target: RegScope,
|
||||
},
|
||||
/// Fetch current registration status
|
||||
#[command(name = "status")]
|
||||
#[command(
|
||||
about = "Fetch the status of registration for given manifest represented application."
|
||||
)]
|
||||
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,
|
||||
},
|
||||
#[command(name = "ext")]
|
||||
#[command(about = "File extension related operations according to given program manifest.")]
|
||||
Ext {
|
||||
@@ -59,10 +95,13 @@ enum CliCommands {
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum CliExtCommands {
|
||||
pub enum CliExtCommands {
|
||||
#[command(name = "link")]
|
||||
#[command(about = "Link user given file extension to the program declared in manifest file.")]
|
||||
Link {
|
||||
/// The scope where link file extension.
|
||||
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = RegScope::User)]
|
||||
target: RegScope,
|
||||
// The file extensions used for this operation. Specify * for all file extension.
|
||||
#[arg(required = true, value_name = "EXTS", num_args = 1..)]
|
||||
exts: Vec<String>,
|
||||
@@ -72,6 +111,9 @@ enum CliExtCommands {
|
||||
about = "Unlink user given file extension from the program declared in manifest file."
|
||||
)]
|
||||
Unlink {
|
||||
/// The scope where unlink file extension.
|
||||
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = RegScope::User)]
|
||||
target: RegScope,
|
||||
// The file extensions used for this operation. Specify * for all file extension.
|
||||
#[arg(required = true, value_name = "EXTS", num_args = 1..)]
|
||||
exts: Vec<String>,
|
||||
@@ -80,37 +122,24 @@ enum CliExtCommands {
|
||||
#[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 {
|
||||
|
||||
List {
|
||||
/// The view where list file extension.
|
||||
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = RegView::User)]
|
||||
target: RegView,
|
||||
/// The style when listing file extensions.
|
||||
#[arg(short = 's', long = "style", value_name = "STYLE", required = true, value_enum, default_value_t = ExtListStyle::Human)]
|
||||
style: ExtListStyle,
|
||||
},
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
/// Parse current commandline argument.
|
||||
///
|
||||
///
|
||||
/// 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();
|
||||
todo!()
|
||||
/// This is the mechanism of `clap` crate.
|
||||
pub fn parse() -> Cli {
|
||||
Cli::parse()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user