diff --git a/src/cli/export_command.rs b/src/cli/export_command.rs index 531d613..83771fe 100644 --- a/src/cli/export_command.rs +++ b/src/cli/export_command.rs @@ -16,45 +16,28 @@ use std::{fs, path::PathBuf}; -use clap::{Args, ValueEnum}; +use clap::Args; use crate::{ - password::{BitWardenPasswords, Passwords}, + password::{BitWardenPasswords, Format, Passwords}, LprsError, LprsResult, RunCommand, }; -#[derive(Clone, Debug, ValueEnum)] -pub enum ExportFormat { - Lprs, - BitWarden, -} - #[derive(Debug, Args)] #[command(author, version, about, long_about = None)] pub struct Export { /// The path to export to path: PathBuf, /// Format to export passwords in - #[arg(short, long, value_name = "FORMAT", default_value_t= ExportFormat::Lprs)] - format: ExportFormat, -} - -impl ToString for ExportFormat { - fn to_string(&self) -> String { - self.to_possible_value() - .expect("There is no skiped values") - .get_name() - .to_owned() - } + #[arg(short, long, value_name = "FORMAT", default_value_t= Format::Lprs)] + format: Format, } impl RunCommand for Export { fn run(&self, password_manager: Passwords) -> LprsResult<()> { let exported_data = match self.format { - ExportFormat::Lprs => serde_json::to_string(&password_manager.encrypt()?.passwords), - ExportFormat::BitWarden => { - serde_json::to_string(&BitWardenPasswords::from(password_manager)) - } + Format::Lprs => serde_json::to_string(&password_manager.encrypt()?.passwords), + Format::BitWarden => serde_json::to_string(&BitWardenPasswords::from(password_manager)), } .map_err(LprsError::from)?; diff --git a/src/password/mod.rs b/src/password/mod.rs index f5693a0..32bbe67 100644 --- a/src/password/mod.rs +++ b/src/password/mod.rs @@ -16,7 +16,7 @@ use std::{fs, path::PathBuf}; -use clap::Parser; +use clap::{Parser, ValueEnum}; use serde::{Deserialize, Serialize}; use crate::{LprsError, LprsResult}; @@ -29,6 +29,12 @@ mod validator; pub use bitwarden::*; pub use validator::*; +#[derive(Clone, Debug, ValueEnum)] +pub enum Format { + Lprs, + BitWarden, +} + /// The password struct #[serde_with_macros::skip_serializing_none] #[derive(Clone, Debug, Deserialize, Serialize, Parser)] @@ -145,3 +151,12 @@ impl Passwords { self.passwords.push(password) } } + +impl ToString for Format { + fn to_string(&self) -> String { + self.to_possible_value() + .expect("There is no skiped values") + .get_name() + .to_owned() + } +}