From 506ff5809e34ce79087b2ddccf8edfca68c4a1d9 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Mon, 25 Nov 2019 22:43:03 -0700 Subject: [PATCH] keygen: Support not writing keypairs to disk (#7136) * keygen: Add flag to prevent new from writing keypair to disk * check_for_overwrite bails, do it before prompts --- keygen/src/keygen.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/keygen/src/keygen.rs b/keygen/src/keygen.rs index 28ec2c0db..73b7f4b43 100644 --- a/keygen/src/keygen.rs +++ b/keygen/src/keygen.rs @@ -78,6 +78,12 @@ fn main() -> Result<(), Box> { .long("no-passphrase") .help("Do not prompt for a passphrase"), ) + .arg( + Arg::with_name("no_outfile") + .long("no-outfile") + .conflicts_with_all(&["outfile", "silent"]) + .help("Only print a seed phrase and pubkey. Do not output a keypair file"), + ) .arg( Arg::with_name("silent") .short("s") @@ -201,14 +207,18 @@ fn main() -> Result<(), Box> { ("new", Some(matches)) => { let mut path = dirs::home_dir().expect("home directory"); let outfile = if matches.is_present("outfile") { - matches.value_of("outfile").unwrap() + matches.value_of("outfile") + } else if matches.is_present("no_outfile") { + None } else { path.extend(&[".config", "solana", "id.json"]); - path.to_str().unwrap() + Some(path.to_str().unwrap()) }; - if outfile != "-" { - check_for_overwrite(&outfile, &matches); + match outfile { + Some("-") => (), + Some(outfile) => check_for_overwrite(&outfile, &matches), + None => (), } let mnemonic = Mnemonic::new(MnemonicType::Words12, Language::English); @@ -223,7 +233,9 @@ fn main() -> Result<(), Box> { let seed = Seed::new(&mnemonic, &passphrase); let keypair = keypair_from_seed(seed.as_bytes())?; - output_keypair(&keypair, &outfile, "new")?; + if let Some(outfile) = outfile { + output_keypair(&keypair, &outfile, "new")?; + } let silent = matches.is_present("silent"); if !silent {