Skip to content
Snippets Groups Projects
Commit 36dca42e authored by dvermd's avatar dvermd
Browse files

[fix] core:commands: #108 rework keys cli options

parent 7d6a36b4
No related branches found
No related tags found
No related merge requests found
......@@ -1031,6 +1031,7 @@ name = "durs-core"
version = "0.3.0-dev"
dependencies = [
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dubp-currency-params 0.2.0",
......
......@@ -11,6 +11,7 @@ path = "src/lib.rs"
[dependencies]
chrono = "0.4"
clap = "2.33.0"
clear_on_drop = "0.2.3"
dirs = "2.0.2"
durs-bc = { path = "../../modules/blockchain/blockchain" }
......@@ -31,6 +32,8 @@ serde = "1.0.*"
serde_derive = "1.0.*"
serde_json = "1.0.*"
structopt= "0.3.4"
#strum = "0.17.1"
#strum_macros = "0.17.1"
unwrap = "1.2.1"
[features]
......@@ -21,6 +21,8 @@ use crate::DursCore;
use clear_on_drop::clear::Clear;
use durs_conf::keys::*;
use durs_conf::DuRsConf;
//use strum_macros::EnumString;
use clap::arg_enum;
#[derive(StructOpt, Debug, Clone)]
#[structopt(
......@@ -90,21 +92,53 @@ pub enum ModifySubCommand {
/// Salt and password of network key
NetworkSaltPassword(SaltPasswordOpt),
}
/*
arg_enum! {
#[derive(StructOpt, Debug, Copy, Clone, PartialEq)]
/// Key to clear: member, network or all (both member and network)
enum ClearOpt {
MEMBER,
NETWORK,
ALL,
}
}
impl ClearOpt {
/// Returns if key kind is member
pub fn is_member(self) -> bool {
self == ClearOpt::MEMBER || self == ClearOpt::ALL
}
/// Returns if key kind is network
pub fn is_network(self) -> bool {
self == ClearOpt::NETWORK || self == ClearOpt::ALL
}
}*/
arg_enum! {
/// KeyKind
#[derive(Debug, Copy, Clone, PartialEq)]
enum KeyKind {
MEMBER,
NETWORK,
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, Copy, Clone)]
/// ClearOpt
pub struct ClearOpt {
#[structopt(short = "m", long = "member")]
/// True if we change member key
pub member: bool,
#[structopt(short = "n", long = "network")]
/// True if we change network key
pub network: bool,
#[structopt(short = "a", long = "all")]
/// True if we change member and network key
pub all: bool,
/// Key to clear
#[structopt(possible_values = &KeyKind::variants(), case_insensitive = true)]
key: KeyKind,
}
#[derive(StructOpt, Debug, Clone)]
......@@ -169,8 +203,8 @@ impl DursExecutableCoreCommand for KeysOpt {
},
KeysSubCommand::Clear(clear_opt) => {
let new_keypairs = clear_keys(
clear_opt.network || clear_opt.all,
clear_opt.member || clear_opt.all,
clear_opt.key.is_network(),
clear_opt.key.is_member(),
keypairs,
);
save_keypairs(profile_path, &keypairs_file, new_keypairs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment