feat: Validate args before ask for the master password #17
11 changed files with 23 additions and 23 deletions
|
@ -18,7 +18,7 @@ use clap::Args;
|
|||
|
||||
use crate::{
|
||||
vault::{vault_state::*, Vault, Vaults},
|
||||
LprsError, LprsResult, RunCommand,
|
||||
LprsCommand, LprsError, LprsResult,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
@ -31,7 +31,7 @@ pub struct Add {
|
|||
password: Option<Option<String>>,
|
||||
}
|
||||
|
||||
impl RunCommand for Add {
|
||||
impl LprsCommand for Add {
|
||||
fn run(mut self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if self.vault_info.username.is_none()
|
||||
&& self.password.is_none()
|
||||
|
|
|
@ -20,14 +20,14 @@ use clap::Args;
|
|||
|
||||
use crate::{
|
||||
vault::{vault_state::*, Vaults},
|
||||
LprsError, LprsResult, RunCommand,
|
||||
LprsCommand, LprsError, LprsResult,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Clean {}
|
||||
|
||||
impl RunCommand for Clean {
|
||||
impl LprsCommand for Clean {
|
||||
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
fs::write(vault_manager.vaults_file, "[]").map_err(LprsError::Io)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use clap::Args;
|
|||
|
||||
use crate::{
|
||||
vault::{vault_state::*, Vault, Vaults},
|
||||
LprsError, LprsResult, RunCommand,
|
||||
LprsCommand, LprsError, LprsResult,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
@ -46,7 +46,7 @@ pub struct Edit {
|
|||
note: Option<String>,
|
||||
}
|
||||
|
||||
impl RunCommand for Edit {
|
||||
impl LprsCommand for Edit {
|
||||
fn run(self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
let index = self.index.get() as usize;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use clap::Args;
|
|||
|
||||
use crate::{
|
||||
vault::{vault_state::*, BitWardenPasswords, Format, Vault, Vaults},
|
||||
LprsError, LprsResult, RunCommand,
|
||||
LprsCommand, LprsError, LprsResult,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
@ -33,7 +33,7 @@ pub struct Export {
|
|||
format: Format,
|
||||
}
|
||||
|
||||
impl RunCommand for Export {
|
||||
impl LprsCommand for Export {
|
||||
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if self
|
||||
.path
|
||||
|
|
|
@ -20,7 +20,7 @@ use clap::Args;
|
|||
|
||||
use crate::{
|
||||
vault::{vault_state::*, Vaults},
|
||||
LprsError, LprsResult, RunCommand,
|
||||
LprsCommand, LprsError, LprsResult,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
@ -44,7 +44,7 @@ pub struct Gen {
|
|||
symbols: bool,
|
||||
}
|
||||
|
||||
impl RunCommand for Gen {
|
||||
impl LprsCommand for Gen {
|
||||
fn run(self, _vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if self.uppercase || self.lowercase || self.numbers || self.symbols {
|
||||
println!(
|
||||
|
|
|
@ -20,7 +20,7 @@ use clap::Args;
|
|||
|
||||
use crate::{
|
||||
vault::{vault_state::*, BitWardenPasswords, Format, Vault, Vaults},
|
||||
LprsError, LprsResult, RunCommand,
|
||||
LprsCommand, LprsError, LprsResult,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
@ -34,7 +34,7 @@ pub struct Import {
|
|||
format: Format,
|
||||
}
|
||||
|
||||
impl RunCommand for Import {
|
||||
impl LprsCommand for Import {
|
||||
fn run(self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if self.path.exists() {
|
||||
if self
|
||||
|
|
|
@ -20,7 +20,7 @@ use clap::Args;
|
|||
|
||||
use crate::{
|
||||
vault::{vault_state::*, Vaults},
|
||||
LprsError, LprsResult, RunCommand,
|
||||
LprsCommand, LprsError, LprsResult,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
@ -49,7 +49,7 @@ pub struct List {
|
|||
regex: bool,
|
||||
}
|
||||
|
||||
impl RunCommand for List {
|
||||
impl LprsCommand for List {
|
||||
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if vault_manager.vaults.is_empty() {
|
||||
return Err(LprsError::Other(
|
||||
|
|
|
@ -18,7 +18,7 @@ use std::path::PathBuf;
|
|||
|
||||
use clap::Parser;
|
||||
|
||||
use crate::{utils, vault::Vaults, LprsResult, RunCommand};
|
||||
use crate::{utils, vault::Vaults, LprsCommand, LprsResult};
|
||||
|
||||
pub mod add_command;
|
||||
pub mod clean_command;
|
||||
|
|
|
@ -20,7 +20,7 @@ use clap::Args;
|
|||
|
||||
use crate::{
|
||||
vault::{vault_state::*, Vaults},
|
||||
LprsError, LprsResult, RunCommand,
|
||||
LprsCommand, LprsError, LprsResult,
|
||||
};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
@ -34,7 +34,7 @@ pub struct Remove {
|
|||
force: bool,
|
||||
}
|
||||
|
||||
impl RunCommand for Remove {
|
||||
impl LprsCommand for Remove {
|
||||
fn run(self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
let index = (self.index.get() - 1) as usize;
|
||||
if index > vault_manager.vaults.len() {
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
||||
|
||||
/// Creates commands macro, to create the `Commands` enum and impl `RunCommand` to it.
|
||||
/// Creates commands macro, to create the `Commands` enum and impl `LprsCommand` to it.
|
||||
///
|
||||
/// ### Notes:
|
||||
/// The `$command` must impl `RunCommand` trait
|
||||
/// The `$command` must impl `LprsCommand` trait
|
||||
///
|
||||
/// ### Example:
|
||||
/// ```rust
|
||||
|
@ -37,7 +37,7 @@
|
|||
/// Some(SomeArgs),
|
||||
/// }
|
||||
///
|
||||
/// impl crate::RunCommand for TestCommands {
|
||||
/// impl crate::LprsCommand for TestCommands {
|
||||
/// fn run(
|
||||
/// &self,
|
||||
/// vault_manager: crate::vault::Vaults,
|
||||
|
@ -62,7 +62,7 @@ macro_rules! create_commands {
|
|||
}
|
||||
|
||||
#[automatically_derived]
|
||||
impl $crate::RunCommand for $enum_name{
|
||||
impl $crate::LprsCommand for $enum_name{
|
||||
fn run(self, vault_manager: $crate::vault::Vaults<$crate::vault::vault_state::Plain>) -> $crate::LprsResult<()> {
|
||||
match self {
|
||||
$(
|
||||
|
|
|
@ -19,7 +19,7 @@ use crate::{
|
|||
LprsResult,
|
||||
};
|
||||
|
||||
/// Trait to run the command
|
||||
pub trait RunCommand {
|
||||
/// Trait to work with the commands
|
||||
pub trait LprsCommand {
|
||||
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue