frost-client: allow removing contacts and groups (#400)
* remove username and password support * remove sqlx dependency * frost-client: allow removing contacts and groups
This commit is contained in:
parent
2a07585b85
commit
0066e508ca
|
@ -44,6 +44,16 @@ pub(crate) enum Command {
|
|||
#[arg(short, long)]
|
||||
config: Option<String>,
|
||||
},
|
||||
/// Remove a contact from the user's address book.
|
||||
RemoveContact {
|
||||
/// The path to the config file to manage. If not specified, it uses
|
||||
/// $HOME/.local/frost/credentials.toml
|
||||
#[arg(short, long)]
|
||||
config: Option<String>,
|
||||
/// The public key of the contact to remove (list with `contacts`).
|
||||
#[arg(short, long)]
|
||||
pubkey: String,
|
||||
},
|
||||
TrustedDealer {
|
||||
/// The path to the config file to manage.
|
||||
///
|
||||
|
@ -81,6 +91,17 @@ pub(crate) enum Command {
|
|||
#[arg(short, long)]
|
||||
config: Option<String>,
|
||||
},
|
||||
/// Remove a group from the config.
|
||||
RemoveGroup {
|
||||
/// The path to the config file to manage. If not specified, it uses
|
||||
/// $HOME/.local/frost/credentials.toml
|
||||
#[arg(short, long)]
|
||||
config: Option<String>,
|
||||
/// The group to remove, identified by the group public key (use
|
||||
/// `groups` to list)
|
||||
#[arg(short, long)]
|
||||
group: String,
|
||||
},
|
||||
Coordinator {
|
||||
/// The path to the config file to manage. If not specified, it uses
|
||||
/// $HOME/.local/frost/credentials.toml
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::error::Error;
|
||||
|
||||
use eyre::eyre;
|
||||
use eyre::{eyre, OptionExt};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{args::Command, config::Config};
|
||||
|
@ -124,3 +124,31 @@ pub(crate) fn list(args: &Command) -> Result<(), Box<dyn Error>> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a contact from the user's address book in the config file.
|
||||
pub(crate) fn remove(args: &Command) -> Result<(), Box<dyn Error>> {
|
||||
let Command::RemoveContact { config, pubkey } = (*args).clone() else {
|
||||
panic!("invalid Command");
|
||||
};
|
||||
|
||||
let mut config = Config::read(config)?;
|
||||
|
||||
let name = config
|
||||
.contact
|
||||
.iter()
|
||||
.find_map(|(name, c)| {
|
||||
if hex::encode(c.pubkey.clone()) == pubkey {
|
||||
Some(name.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.clone()
|
||||
.ok_or_eyre("contact not found")?;
|
||||
|
||||
config.contact.remove(&name);
|
||||
|
||||
config.write()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use std::error::Error;
|
||||
|
||||
use eyre::OptionExt;
|
||||
|
||||
use crate::{args::Command, config::Config};
|
||||
|
||||
pub(crate) fn list(args: &Command) -> Result<(), Box<dyn Error>> {
|
||||
|
@ -16,3 +18,18 @@ pub(crate) fn list(args: &Command) -> Result<(), Box<dyn Error>> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a group from the user's config file.
|
||||
pub(crate) fn remove(args: &Command) -> Result<(), Box<dyn Error>> {
|
||||
let Command::RemoveGroup { config, group } = (*args).clone() else {
|
||||
panic!("invalid Command");
|
||||
};
|
||||
|
||||
let mut config = Config::read(config)?;
|
||||
|
||||
config.group.remove(&group).ok_or_eyre("group not found")?;
|
||||
|
||||
config.write()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -24,7 +24,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
Command::Export { .. } => contact::export(&args.command),
|
||||
Command::Import { .. } => contact::import(&args.command),
|
||||
Command::Contacts { .. } => contact::list(&args.command),
|
||||
Command::RemoveContact { .. } => contact::remove(&args.command),
|
||||
Command::Groups { .. } => group::list(&args.command),
|
||||
Command::RemoveGroup { .. } => group::remove(&args.command),
|
||||
Command::TrustedDealer { .. } => trusted_dealer::trusted_dealer(&args.command),
|
||||
Command::Coordinator { .. } => crate::coordinator::run(&args.command).await,
|
||||
Command::Participant { .. } => crate::participant::run(&args.command).await,
|
||||
|
|
Loading…
Reference in New Issue