Skip to content

Commit

Permalink
add num args, version
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Apr 3, 2024
1 parent d00855e commit 7b558bd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bincode = "1"
bitvec = "1"
byteorder = "1"
bytes = "1"
clap = "4.5.1"
clap = { version = "4.5.1", features = ["cargo"] }
compare_fields_derive = { path = "common/compare_fields_derive" }
criterion = "0.3"
delay_map = "0.3"
Expand Down
36 changes: 17 additions & 19 deletions account_manager/src/wallet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,27 @@ pub fn cli_app() -> Command {
.value_name("MNEMONIC_LENGTH")
.help("The number of words to use for the mnemonic phrase.")
.action(ArgAction::Set)
.value_parser(check_mnemonic_length)
.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"),
)
}

fn check_mnemonic_length(len: &str) -> Result<String, String> {
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(", ")
)),
}
}

pub fn cli_run(matches: &ArgMatches, wallet_base_dir: PathBuf) -> Result<(), String> {
let mnemonic_output_path: Option<PathBuf> = clap_utils::parse_optional(matches, MNEMONIC_FLAG)?;

Expand Down
8 changes: 4 additions & 4 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use clap::{builder::ArgPredicate, Arg, ArgAction, ArgGroup, Command};
use clap::{builder::ArgPredicate, Arg, ArgAction, ArgGroup, Command, crate_version};
use clap_utils::get_color_style;
use strum::VariantNames;
use types::ProgressiveBalancesMode;

pub fn cli_app() -> Command {
Command::new("beacon_node")
.visible_aliases(["b", "bn", "beacon"])
//.version(crate_version!())
.version(crate_version!())
.author("Sigma Prime <[email protected]>")
.styles(get_color_style())
.about("The primary component which connects to the Ethereum 2.0 P2P network and \
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn cli_app() -> Command {
IPv4 and IPv6. The order of the given addresses is not relevant. However, \
multiple IPv4, or multiple IPv6 addresses will not be accepted.")
.action(ArgAction::Append)
// .max_values(2)
.num_args(0..=2)
.default_value("0.0.0.0")
)
.arg(
Expand Down Expand Up @@ -239,7 +239,7 @@ pub fn cli_app() -> Command {
local node on this address. This will update the `ip4` or `ip6` ENR fields \
accordingly. To update both, set this flag twice with the different values.")
.action(ArgAction::Append)
// .max_values(2)
.num_args(0..=2)
)
.arg(
Arg::new("enr-match")
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,10 +1430,9 @@ pub fn set_network_config(
if config_str.as_str() == "disabled" {
None
} else {
// Enabled with a custom configuration
Some(config_str.parse()?)
}
// Enabled with a custom configuration
// Some(config_str.parse()?)
}
};
Ok(())
Expand Down
7 changes: 3 additions & 4 deletions boot_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn cli_app() -> Command {
local node on this address. This will update the `ip4` or `ip6` ENR fields \
accordingly. To update both, set this flag twice with the different values.")
.action(ArgAction::Append)
// .max_values(2)
.num_args(0..=2)
.required(true)
.conflicts_with("network-dir")
)
Expand Down Expand Up @@ -56,10 +56,9 @@ pub fn cli_app() -> Command {
- --listen-address '0.0.0.0' --listen-address '::' will listen over both \
Ipv4 and Ipv6. The order of the given addresses is not relevant. However, \
multiple Ipv4, or multiple Ipv6 addresses will not be accepted.")
// .multiple(true)
// .max_values(2)
.num_args(0..=2)
.default_value("0.0.0.0")
.action(ArgAction::Set)
.action(ArgAction::Append)
)
.arg(
Arg::new("boot-nodes")
Expand Down
4 changes: 2 additions & 2 deletions testing/simulator/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use clap::{Arg, ArgAction, Command};
use clap::{Arg, ArgAction, Command, crate_version};

pub fn cli_app() -> Command {
Command::new("simulator")
// .version(crate_version!())
.version(crate_version!())
.author("Sigma Prime <[email protected]>")
.about("Options for interacting with simulator")
.subcommand(
Expand Down

0 comments on commit 7b558bd

Please sign in to comment.