|
|
|
|
@ -15,22 +15,40 @@ use std::path::PathBuf;
|
|
|
|
|
#[derive(Subcommand, Debug, Clone)] |
|
|
|
|
pub enum Command { |
|
|
|
|
/// Decode a word using given system
|
|
|
|
|
Decode(decode::DecodeArgs), |
|
|
|
|
Decode(decode::DecodeCmd), |
|
|
|
|
|
|
|
|
|
/// Encode a number using given system
|
|
|
|
|
Encode(encode::EncodeArgs), |
|
|
|
|
Encode(encode::EncodeCmd), |
|
|
|
|
|
|
|
|
|
/// Import dictionary
|
|
|
|
|
ImportDict(import_dict::ImportDictArgs), |
|
|
|
|
ImportDict(import_dict::ImportDictCmd), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn resolve_command(command: &Command) -> &dyn AppCommand { |
|
|
|
|
match command { |
|
|
|
|
Command::Decode(args) => args, |
|
|
|
|
Command::Encode(args) => args, |
|
|
|
|
Command::ImportDict(args) => args, |
|
|
|
|
impl Command { |
|
|
|
|
pub fn into_app_command(self) -> Box<dyn AppCommand> { |
|
|
|
|
match self { |
|
|
|
|
Command::Decode(cmd) => Box::new(cmd), |
|
|
|
|
Command::Encode(cmd) => Box::new(cmd), |
|
|
|
|
Command::ImportDict(cmd) => Box::new(cmd), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// pub fn resolve_command(command: &Command) -> &dyn AppCommand {
|
|
|
|
|
// match command {
|
|
|
|
|
// Command::Decode(app_cmd) => app_cmd,
|
|
|
|
|
// Command::Encode(app_cmd) => app_cmd,
|
|
|
|
|
// Command::ImportDict(app_cmd) => app_cmd,
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// pub fn resolve_command_box(command: Command) -> Box<dyn AppCommand> {
|
|
|
|
|
// match command {
|
|
|
|
|
// Command::Decode(cmd) => Box::new(cmd),
|
|
|
|
|
// Command::Encode(cmd) => Box::new(cmd),
|
|
|
|
|
// Command::ImportDict(cmd) => Box::new(cmd),
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)] |
|
|
|
|
#[command(author, version, about)] |
|
|
|
|
@ -52,7 +70,7 @@ pub struct GlobalArgs {
|
|
|
|
|
pub log_level: Option<String>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub trait ConfigurableCommand { |
|
|
|
|
pub trait Configurable { |
|
|
|
|
fn apply_defaults( |
|
|
|
|
&self, |
|
|
|
|
builder: ConfigBuilder<DefaultState>, |
|
|
|
|
@ -64,15 +82,15 @@ pub trait ConfigurableCommand {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[async_trait] |
|
|
|
|
pub trait CommandExecutor { |
|
|
|
|
pub trait Executable { |
|
|
|
|
async fn execute(&self, config: &AppConfig, container: &Container) -> Result<()>; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// AppCommand must be dyn-compatible. ConfigurableCommand is already dyn-compatible.
|
|
|
|
|
// CommandExecutor is dyn-compatible because of #[async_trait].
|
|
|
|
|
pub trait AppCommand: ConfigurableCommand + CommandExecutor {} |
|
|
|
|
// AppCommand must be dyn-compatible. Configurable is already dyn-compatible.
|
|
|
|
|
// Executable is dyn-compatible because of #[async_trait].
|
|
|
|
|
pub trait AppCommand: Configurable + Executable {} |
|
|
|
|
|
|
|
|
|
impl<T: ConfigurableCommand + CommandExecutor> AppCommand for T {} |
|
|
|
|
impl<T: Configurable + Executable> AppCommand for T {} |
|
|
|
|
|
|
|
|
|
mod defaults { |
|
|
|
|
use const_format::formatcp; |
|
|
|
|
|