From a6870b2dcabc73427a56334b5a0ea45930f42f26 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Thu, 25 Apr 2024 08:29:54 +0300 Subject: [PATCH] chore: Ctrate `LprsCommand::validate_args` function This function will validate the args of the command before ask the user for the master password --- src/cli/mod.rs | 2 ++ src/macros.rs | 8 ++++++++ src/traits.rs | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 933f75b..a5c2424 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -63,6 +63,8 @@ impl Cli { }; log::debug!("Getting the vaults file: {}", vaults_file.to_string_lossy()); + self.command.validate_args()?; + let vault_manager = if matches!(self.command, Commands::Clean(..) | Commands::Gen(..)) { // Returns empty vault manager for those commands don't need it Vaults { diff --git a/src/macros.rs b/src/macros.rs index aab1c8c..69f2777 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -70,6 +70,14 @@ macro_rules! create_commands { )+ } } + + fn validate_args(&self) -> LprsResult<()> { + match self { + $( + Self::$varint(command) => command.validate_args(), + )+ + } + } } }; } diff --git a/src/traits.rs b/src/traits.rs index c48b693..708829a 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -21,5 +21,11 @@ use crate::{ /// Trait to work with the commands pub trait LprsCommand { + /// Run the command, should do all the logic, even the export fn run(self, vault_manager: Vaults) -> LprsResult<()>; + + /// Validate the gaiven args from the user. + fn validate_args(&self) -> LprsResult<()> { + Ok(()) + } }