solana_clap_v3_utils/keygen/
mod.rs1use {
2 crate::{
3 keygen::mnemonic::{language_arg, no_passphrase_arg, word_count_arg},
4 ArgConstant,
5 },
6 clap::{Arg, ArgMatches, Command},
7 std::{error, path::Path},
8};
9
10pub mod derivation_path;
11pub mod mnemonic;
12
13pub const NO_OUTFILE_ARG: ArgConstant<'static> = ArgConstant {
14 long: "no-outfile",
15 name: "no_outfile",
16 help: "Only print a seed phrase and pubkey. Do not output a keypair file",
17};
18
19pub fn no_outfile_arg<'a>() -> Arg<'a> {
20 Arg::new(NO_OUTFILE_ARG.name)
21 .long(NO_OUTFILE_ARG.long)
22 .help(NO_OUTFILE_ARG.help)
23}
24
25pub trait KeyGenerationCommonArgs {
26 fn key_generation_common_args(self) -> Self;
27}
28
29impl KeyGenerationCommonArgs for Command<'_> {
30 fn key_generation_common_args(self) -> Self {
31 self.arg(word_count_arg())
32 .arg(language_arg())
33 .arg(no_passphrase_arg())
34 }
35}
36
37pub fn check_for_overwrite(
38 outfile: &str,
39 matches: &ArgMatches,
40) -> Result<(), Box<dyn error::Error>> {
41 let force = matches.try_contains_id("force")?;
42 if !force && Path::new(outfile).exists() {
43 let err_msg = format!("Refusing to overwrite {outfile} without --force flag");
44 return Err(err_msg.into());
45 }
46 Ok(())
47}