feat: Ability to enter password via stdin add
&edit
#15
10 changed files with 10 additions and 10 deletions
|
@ -29,7 +29,7 @@ pub struct Add {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunCommand for Add {
|
impl RunCommand for Add {
|
||||||
fn run(&self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
fn run(self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||||
if self.vault_info.username.is_none()
|
if self.vault_info.username.is_none()
|
||||||
&& self.vault_info.password.is_none()
|
&& self.vault_info.password.is_none()
|
||||||
&& self.vault_info.service.is_none()
|
&& self.vault_info.service.is_none()
|
||||||
|
|
|
@ -28,7 +28,7 @@ use crate::{
|
||||||
pub struct Clean {}
|
pub struct Clean {}
|
||||||
|
|
||||||
impl RunCommand for Clean {
|
impl RunCommand for Clean {
|
||||||
fn run(&self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||||
fs::write(vault_manager.vaults_file, "[]").map_err(LprsError::Io)
|
fs::write(vault_manager.vaults_file, "[]").map_err(LprsError::Io)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub struct Edit {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunCommand for Edit {
|
impl RunCommand for Edit {
|
||||||
fn run(&self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
fn run(self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||||
let index = self.index.get() as usize;
|
let index = self.index.get() as usize;
|
||||||
|
|
||||||
if let Some(vault) = vault_manager.vaults.get_mut(index - 1) {
|
if let Some(vault) = vault_manager.vaults.get_mut(index - 1) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub struct Export {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunCommand for Export {
|
impl RunCommand for Export {
|
||||||
fn run(&self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||||
if self
|
if self
|
||||||
.path
|
.path
|
||||||
.extension()
|
.extension()
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub struct Gen {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunCommand for Gen {
|
impl RunCommand for Gen {
|
||||||
fn run(&self, _vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
fn run(self, _vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||||
if self.uppercase || self.lowercase || self.numbers || self.symbols {
|
if self.uppercase || self.lowercase || self.numbers || self.symbols {
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub struct Import {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunCommand for Import {
|
impl RunCommand for Import {
|
||||||
fn run(&self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
fn run(self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||||
if self.path.exists() {
|
if self.path.exists() {
|
||||||
if self
|
if self
|
||||||
.path
|
.path
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub struct List {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunCommand for List {
|
impl RunCommand for List {
|
||||||
fn run(&self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||||
if vault_manager.vaults.is_empty() {
|
if vault_manager.vaults.is_empty() {
|
||||||
return Err(LprsError::Other(
|
return Err(LprsError::Other(
|
||||||
"Looks like there is no passwords to list".to_owned(),
|
"Looks like there is no passwords to list".to_owned(),
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub struct Remove {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunCommand for Remove {
|
impl RunCommand for Remove {
|
||||||
fn run(&self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
fn run(self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||||
let index = (self.index.get() - 1) as usize;
|
let index = (self.index.get() - 1) as usize;
|
||||||
if index > vault_manager.vaults.len() {
|
if index > vault_manager.vaults.len() {
|
||||||
if !self.force {
|
if !self.force {
|
||||||
|
|
|
@ -63,7 +63,7 @@ macro_rules! create_commands {
|
||||||
|
|
||||||
#[automatically_derived]
|
#[automatically_derived]
|
||||||
impl $crate::RunCommand for $enum_name{
|
impl $crate::RunCommand for $enum_name{
|
||||||
fn run(&self, vault_manager: $crate::vault::Vaults<$crate::vault::vault_state::Plain>) -> $crate::LprsResult<()> {
|
fn run(self, vault_manager: $crate::vault::Vaults<$crate::vault::vault_state::Plain>) -> $crate::LprsResult<()> {
|
||||||
match self {
|
match self {
|
||||||
$(
|
$(
|
||||||
Self::$varint(command) => command.run(vault_manager),
|
Self::$varint(command) => command.run(vault_manager),
|
||||||
|
|
|
@ -21,5 +21,5 @@ use crate::{
|
||||||
|
|
||||||
/// Trait to run the command
|
/// Trait to run the command
|
||||||
pub trait RunCommand {
|
pub trait RunCommand {
|
||||||
fn run(&self, vault_manager: Vaults<Plain>) -> LprsResult<()>;
|
fn run(self, vault_manager: Vaults<Plain>) -> LprsResult<()>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue