mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-09 03:08:33 +00:00
upgrade clap to v4.5 (#5273)
* upgrade clap to v4.5 * cli fixes * Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli * value parser for mnemonic * Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli * merge unstable * default --format val * fix eth sim * fix eth sim * merge conflicts * resolve beta compiler issue * add num args, version * add custom flag parser, make rate limiter flags clap friendly * remove unneeded check * fmt * update * alphabetic order * resolve merge conflict * fix test * resolve conflicts * fix test * revert removed if statement * fmt got me again * fix broken flag * make cli * make cli * update * remove -e files * update * cli help updates * Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli * cli help updates * md files * merge conflict * merge conflicts * md * help text, text width, and a few flag fixes * fmt * merge * revert * revert * resolve merge conflicts * merge conflicts * revert simulator changes * require at least one arg * fix eth sim cli * resolve merge conflicts * book changes * md changes * cli check * cli check * retry cli check * retry cli check * Merge branch 'unstable' of https://github.com/sigp/lighthouse into upgrade-clap-cli * cli * Merge remote-tracking branch 'origin/unstable' into upgrade-clap-cli * Update CLI docs for Goerli removal * Fix cargo lock
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::WALLETS_DIR_FLAG;
|
||||
use account_utils::{
|
||||
is_password_sufficiently_complex, random_password, read_password_from_user, strip_off_newlines,
|
||||
};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||
use eth2_wallet::{
|
||||
bip39::{Language, Mnemonic, MnemonicType},
|
||||
PlainText,
|
||||
@@ -33,21 +33,22 @@ pub const NEW_WALLET_PASSWORD_PROMPT: &str =
|
||||
"Enter a password for your new wallet that is at least 12 characters long:";
|
||||
pub const RETYPE_PASSWORD_PROMPT: &str = "Please re-enter your wallet's new password:";
|
||||
|
||||
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
App::new(CMD)
|
||||
pub fn cli_app() -> Command {
|
||||
Command::new(CMD)
|
||||
.about("Creates a new HD (hierarchical-deterministic) EIP-2386 wallet.")
|
||||
.arg(
|
||||
Arg::with_name(NAME_FLAG)
|
||||
Arg::new(NAME_FLAG)
|
||||
.long(NAME_FLAG)
|
||||
.value_name("WALLET_NAME")
|
||||
.help(
|
||||
"The wallet will be created with this name. It is not allowed to \
|
||||
create two wallets with the same name for the same --base-dir.",
|
||||
)
|
||||
.takes_value(true),
|
||||
.action(ArgAction::Set)
|
||||
.display_order(0)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(PASSWORD_FLAG)
|
||||
Arg::new(PASSWORD_FLAG)
|
||||
.long(PASSWORD_FLAG)
|
||||
.value_name("WALLET_PASSWORD_PATH")
|
||||
.help(
|
||||
@@ -56,49 +57,65 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
saved at that path. To avoid confusion, if the file does not already \
|
||||
exist it must include a '.pass' suffix.",
|
||||
)
|
||||
.takes_value(true),
|
||||
.action(ArgAction::Set)
|
||||
.display_order(0)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(TYPE_FLAG)
|
||||
Arg::new(TYPE_FLAG)
|
||||
.long(TYPE_FLAG)
|
||||
.value_name("WALLET_TYPE")
|
||||
.help(
|
||||
"The type of wallet to create. Only HD (hierarchical-deterministic) \
|
||||
wallets are supported presently..",
|
||||
)
|
||||
.takes_value(true)
|
||||
.possible_values(&[HD_TYPE])
|
||||
.default_value(HD_TYPE),
|
||||
.action(ArgAction::Set)
|
||||
.value_parser([HD_TYPE])
|
||||
.default_value(HD_TYPE)
|
||||
.display_order(0)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(MNEMONIC_FLAG)
|
||||
Arg::new(MNEMONIC_FLAG)
|
||||
.long(MNEMONIC_FLAG)
|
||||
.value_name("MNEMONIC_PATH")
|
||||
.help(
|
||||
"If present, the mnemonic will be saved to this file. DO NOT SHARE THE MNEMONIC.",
|
||||
)
|
||||
.takes_value(true)
|
||||
.action(ArgAction::Set)
|
||||
.display_order(0)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(STDIN_INPUTS_FLAG)
|
||||
.takes_value(false)
|
||||
.hidden(cfg!(windows))
|
||||
Arg::new(STDIN_INPUTS_FLAG)
|
||||
.action(ArgAction::SetTrue)
|
||||
.hide(cfg!(windows))
|
||||
.long(STDIN_INPUTS_FLAG)
|
||||
.help("If present, read all user inputs from stdin instead of tty."),
|
||||
.help("If present, read all user inputs from stdin instead of tty.")
|
||||
.display_order(0)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(MNEMONIC_LENGTH_FLAG)
|
||||
Arg::new(MNEMONIC_LENGTH_FLAG)
|
||||
.long(MNEMONIC_LENGTH_FLAG)
|
||||
.value_name("MNEMONIC_LENGTH")
|
||||
.help("The number of words to use for the mnemonic phrase.")
|
||||
.takes_value(true)
|
||||
.validator(|len| {
|
||||
match len.parse::<usize>().ok().and_then(|words| MnemonicType::for_word_count(words).ok()) {
|
||||
Some(_) => Ok(()),
|
||||
None => Err(format!("Mnemonic length must be one of {}", MNEMONIC_TYPES.iter().map(|t| t.word_count().to_string()).collect::<Vec<_>>().join(", "))),
|
||||
}
|
||||
.action(ArgAction::Set)
|
||||
.value_parser(|len: &str| {
|
||||
match len
|
||||
.parse::<usize>()
|
||||
.ok()
|
||||
.and_then(|words| MnemonicType::for_word_count(words).ok())
|
||||
{
|
||||
Some(_) => Ok(len.to_string()),
|
||||
None => Err(format!(
|
||||
"Mnemonic length must be one of {}",
|
||||
MNEMONIC_TYPES
|
||||
.iter()
|
||||
.map(|t| t.word_count().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)),
|
||||
}
|
||||
})
|
||||
.default_value("24"),
|
||||
.default_value("24")
|
||||
.display_order(0)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -153,7 +170,7 @@ pub fn create_wallet_from_mnemonic(
|
||||
let name: Option<String> = clap_utils::parse_optional(matches, NAME_FLAG)?;
|
||||
let wallet_password_path: Option<PathBuf> = clap_utils::parse_optional(matches, PASSWORD_FLAG)?;
|
||||
let type_field: String = clap_utils::parse_required(matches, TYPE_FLAG)?;
|
||||
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);
|
||||
let stdin_inputs = cfg!(windows) || matches.get_flag(STDIN_INPUTS_FLAG);
|
||||
let wallet_type = match type_field.as_ref() {
|
||||
HD_TYPE => WalletType::Hd,
|
||||
unknown => return Err(format!("--{} {} is not supported", TYPE_FLAG, unknown)),
|
||||
|
||||
Reference in New Issue
Block a user