Skip to content
Snippets Groups Projects

Resolve "Keys clean subcommand : Indicate to Structopt that the user must indicate which keypair to delete"

Files
3
@@ -21,6 +21,7 @@ use crate::DursCore;
@@ -21,6 +21,7 @@ use crate::DursCore;
use clear_on_drop::clear::Clear;
use clear_on_drop::clear::Clear;
use durs_conf::keys::*;
use durs_conf::keys::*;
use durs_conf::DuRsConf;
use durs_conf::DuRsConf;
 
use strum_macros::EnumString;
#[derive(StructOpt, Debug, Clone)]
#[derive(StructOpt, Debug, Clone)]
#[structopt(
#[structopt(
@@ -94,17 +95,29 @@ pub enum ModifySubCommand {
@@ -94,17 +95,29 @@ pub enum ModifySubCommand {
#[derive(StructOpt, Debug, Copy, Clone)]
#[derive(StructOpt, Debug, Copy, Clone)]
/// ClearOpt
/// ClearOpt
pub struct ClearOpt {
pub struct ClearOpt {
#[structopt(short = "m", long = "member")]
/// Key to clear: member, network or all (both member and network)
/// True if we change member key
key: KeyKind,
pub member: bool,
}
#[derive(Debug, Copy, Clone, PartialEq, EnumString)]
#[structopt(short = "n", long = "network")]
#[strum(serialize_all = "kebab_case")]
/// True if we change network key
/// KeyKind
pub network: bool,
pub enum KeyKind {
/// Member key
#[structopt(short = "a", long = "all")]
MEMBER,
/// True if we change member and network key
/// Network key
pub all: bool,
NETWORK,
 
/// Both Member and Network keys
 
ALL,
 
}
 
impl KeyKind {
 
/// Returns if key kind is member
 
pub fn is_member(self) -> bool {
 
self == KeyKind::MEMBER || self == KeyKind::ALL
 
}
 
/// Returns if key kind is network
 
pub fn is_network(self) -> bool {
 
self == KeyKind::NETWORK || self == KeyKind::ALL
 
}
}
}
#[derive(StructOpt, Debug, Clone)]
#[derive(StructOpt, Debug, Clone)]
@@ -169,8 +182,8 @@ impl DursExecutableCoreCommand for KeysOpt {
@@ -169,8 +182,8 @@ impl DursExecutableCoreCommand for KeysOpt {
},
},
KeysSubCommand::Clear(clear_opt) => {
KeysSubCommand::Clear(clear_opt) => {
let new_keypairs = clear_keys(
let new_keypairs = clear_keys(
clear_opt.network || clear_opt.all,
clear_opt.key.is_network(),
clear_opt.member || clear_opt.all,
clear_opt.key.is_member(),
keypairs,
keypairs,
);
);
save_keypairs(profile_path, &keypairs_file, new_keypairs)
save_keypairs(profile_path, &keypairs_file, new_keypairs)
Loading