feat: use rust_util use_clap

This commit is contained in:
2021-01-03 10:58:29 +08:00
parent 8b70dfa145
commit 740d5baf65
11 changed files with 44 additions and 71 deletions

View File

@@ -1,7 +1,7 @@
use std::fs;
use std::fs::File;
use clap::{App, Arg, ArgMatches, SubCommand};
use crate::cmd::{Command, CommandError};
use rust_util::util_clap::{Command, CommandError};
use crate::util::{JsonKeyPair, make_key_pair};
pub struct CommandImpl;
@@ -21,12 +21,12 @@ impl Command for CommandImpl {
let tag = sub_arg_matches.value_of("tag");
if let Ok(_) = File::open(output) {
failure!("Output file exists: {}", output);
return Ok(());
return Ok(None);
}
let (pri_key, pub_key) = make_key_pair();
let json_key_pair = JsonKeyPair::from(pri_key, pub_key, tag.map(|t| t.into()));
success!("Write gen key file: {}", output);
fs::write(output, json_key_pair.to_json()?.as_bytes())?;
Ok(())
Ok(None)
}
}