chore: Ctrate LprsCommand::validate_args
function
This function will validate the args of the command before ask the user for the master password
This commit is contained in:
parent
21429104a3
commit
a6870b2dca
3 changed files with 16 additions and 0 deletions
|
@ -63,6 +63,8 @@ impl Cli {
|
||||||
};
|
};
|
||||||
log::debug!("Getting the vaults file: {}", vaults_file.to_string_lossy());
|
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(..)) {
|
let vault_manager = if matches!(self.command, Commands::Clean(..) | Commands::Gen(..)) {
|
||||||
// Returns empty vault manager for those commands don't need it
|
// Returns empty vault manager for those commands don't need it
|
||||||
Vaults {
|
Vaults {
|
||||||
|
|
|
@ -70,6 +70,14 @@ macro_rules! create_commands {
|
||||||
)+
|
)+
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn validate_args(&self) -> LprsResult<()> {
|
||||||
|
match self {
|
||||||
|
$(
|
||||||
|
Self::$varint(command) => command.validate_args(),
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,5 +21,11 @@ use crate::{
|
||||||
|
|
||||||
/// Trait to work with the commands
|
/// Trait to work with the commands
|
||||||
pub trait LprsCommand {
|
pub trait LprsCommand {
|
||||||
|
/// Run the command, should do all the logic, even the export
|
||||||
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()>;
|
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()>;
|
||||||
|
|
||||||
|
/// Validate the gaiven args from the user.
|
||||||
|
fn validate_args(&self) -> LprsResult<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue