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:
Eitan Seri-Levi
2024-05-28 07:46:39 +02:00
committed by GitHub
parent 6a7305a487
commit df983a83e1
61 changed files with 4036 additions and 2868 deletions

View File

@@ -1,4 +1,4 @@
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgAction, ArgMatches, Command};
use environment::Environment;
use slashing_protection::{
interchange::Interchange, InterchangeError, InterchangeImportOutcome, SlashingDatabase,
@@ -18,43 +18,47 @@ pub const EXPORT_FILE_ARG: &str = "EXPORT-FILE";
pub const PUBKEYS_FLAG: &str = "pubkeys";
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
pub fn cli_app() -> Command {
Command::new(CMD)
.about("Import or export slashing protection data to or from another client")
.display_order(0)
.subcommand(
App::new(IMPORT_CMD)
Command::new(IMPORT_CMD)
.about("Import an interchange file")
.arg(
Arg::with_name(IMPORT_FILE_ARG)
.takes_value(true)
Arg::new(IMPORT_FILE_ARG)
.action(ArgAction::Set)
.value_name("FILE")
.display_order(0)
.help("The slashing protection interchange file to import (.json)"),
)
)
.subcommand(
App::new(EXPORT_CMD)
Command::new(EXPORT_CMD)
.about("Export an interchange file")
.arg(
Arg::with_name(EXPORT_FILE_ARG)
.takes_value(true)
Arg::new(EXPORT_FILE_ARG)
.action(ArgAction::Set)
.value_name("FILE")
.help("The filename to export the interchange file to"),
.help("The filename to export the interchange file to")
.display_order(0)
)
.arg(
Arg::with_name(PUBKEYS_FLAG)
Arg::new(PUBKEYS_FLAG)
.long(PUBKEYS_FLAG)
.takes_value(true)
.action(ArgAction::Set)
.value_name("PUBKEYS")
.help(
"List of public keys to export history for. Keys should be 0x-prefixed, \
comma-separated. All known keys will be exported if omitted",
),
)
.display_order(0)
)
)
}
pub fn cli_run<E: EthSpec>(
matches: &ArgMatches<'_>,
matches: &ArgMatches,
env: Environment<E>,
validator_base_dir: PathBuf,
) -> Result<(), String> {
@@ -68,7 +72,7 @@ pub fn cli_run<E: EthSpec>(
.ok_or_else(|| "Unable to get genesis state, has genesis occurred?".to_string())?;
match matches.subcommand() {
(IMPORT_CMD, Some(matches)) => {
Some((IMPORT_CMD, matches)) => {
let import_filename: PathBuf = clap_utils::parse_required(matches, IMPORT_FILE_ARG)?;
let import_file = File::open(&import_filename).map_err(|e| {
format!(
@@ -168,7 +172,7 @@ pub fn cli_run<E: EthSpec>(
Ok(())
}
(EXPORT_CMD, Some(matches)) => {
Some((EXPORT_CMD, matches)) => {
let export_filename: PathBuf = clap_utils::parse_required(matches, EXPORT_FILE_ARG)?;
let selected_pubkeys = if let Some(pubkeys) =
@@ -215,7 +219,7 @@ pub fn cli_run<E: EthSpec>(
Ok(())
}
("", _) => Err("No subcommand provided, see --help for options".to_string()),
(command, _) => Err(format!("No such subcommand `{}`", command)),
Some((command, _)) => Err(format!("No such subcommand `{}`", command)),
_ => Err("No subcommand provided, see --help for options".to_string()),
}
}