From 952e55038bef0b88ec7952cd10d04e9bb1a6ffd9 Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:57:45 +0900 Subject: [PATCH] :recycle: impl Command for Cli --- cli/src/command.rs | 9 ++++++++- cli/src/main.rs | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 7f17a4be..23e012be 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -61,6 +61,13 @@ fn check_password(password: &Option, cipher_args: &CipherAlgorithmArgs) } } -trait Command { +pub trait Command { fn execute(self) -> io::Result<()>; } + +impl Command for Cli { + #[inline] + fn execute(self) -> io::Result<()> { + entry(self) + } +} diff --git a/cli/src/main.rs b/cli/src/main.rs index c277a434..d06212ec 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -5,13 +5,14 @@ mod ext; mod utils; use clap::Parser; +use command::Command; use log::Level; use std::io; fn main() -> io::Result<()> { - let args = cli::Cli::parse(); - init_logger(args.verbosity.log_level_filter())?; - command::entry(args) + let cli = cli::Cli::parse(); + init_logger(cli.verbosity.log_level_filter())?; + cli.execute() } fn init_logger(level: log::LevelFilter) -> io::Result<()> {