1
0
Files
wfassoc/wfassoc_exec/src/cli.rs

117 lines
3.2 KiB
Rust
Raw Normal View History

use clap::{Parser, Subcommand, ValueEnum};
2025-12-30 23:21:01 +08:00
// region: Clap Declaration
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ValueEnum)]
enum Target {
#[value(name = "user")]
User,
#[value(name = "system")]
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)]
2025-12-30 23:21:01 +08:00
struct Cli {
/// The TOML manifest file representing the complete program
2025-10-17 14:19:26 +08:00
#[arg(
2025-12-30 23:21:01 +08:00
short = 'm',
long = "manifest",
value_name = "PROG_MANIFEST",
2025-10-17 14:19:26 +08:00
required = true
)]
2025-12-30 23:21:01 +08:00
manifest_file: String,
2025-10-17 14:19:26 +08:00
#[command(subcommand)]
2025-12-30 23:21:01 +08:00
command: CliCommands,
2025-10-17 14:19:26 +08:00
}
#[derive(Subcommand)]
2025-12-30 23:21:01 +08:00
enum CliCommands {
2025-10-17 14:19:26 +08:00
/// Register the program
#[command(name = "register")]
#[command(about = "Register application with given manifest and scope.")]
Register {
/// The scope where wfassoc operate
2025-12-30 23:21:01 +08:00
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = Target::User)]
target: Target,
},
2025-10-17 14:19:26 +08:00
/// Unregister the program
#[command(name = "unregister")]
#[command(about = "Unregister application with given manifest and scope.")]
Unregister {
/// The scope where wfassoc operate
2025-12-30 23:21:01 +08:00
#[arg(short = 't', long = "target", value_name = "TARGET", required = true, value_enum, default_value_t = Target::User)]
target: Target,
},
2025-12-30 23:21:01 +08:00
/// 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();
2025-10-17 14:19:26 +08:00
}