Skip to content

Commit

Permalink
Move get_testnet_dir to clap utils
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Aug 17, 2020
1 parent d1d269a commit 53892af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
18 changes: 1 addition & 17 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use beacon_chain::builder::PUBKEY_CACHE_FILENAME;
use clap::ArgMatches;
use clap_utils::BAD_TESTNET_DIR_MESSAGE;
use clap_utils::{get_testnet_dir, BAD_TESTNET_DIR_MESSAGE};
use client::{config::DEFAULT_DATADIR, ClientConfig, ClientGenesis};
use eth2_libp2p::{multiaddr::Protocol, Enr, Multiaddr};
use eth2_testnet_config::Eth2TestnetConfig;
Expand All @@ -15,7 +15,6 @@ use types::{ChainSpec, EthSpec, GRAFFITI_BYTES_LEN};

pub const BEACON_NODE_DIR: &str = "beacon";
pub const NETWORK_DIR: &str = "network";
pub const CUSTOM_TESTNET_DIR: &str = "custom";

/// Gets the fully-initialized global client.
///
Expand Down Expand Up @@ -410,21 +409,6 @@ pub fn get_data_dir(cli_args: &ArgMatches) -> PathBuf {
.unwrap_or_else(|| PathBuf::from("."))
}

/// Gets the testnet directory name
///
/// Tries to get the name first from the "testnet" flag,
/// if not present, then checks the "testnet-dir" flag and returns a custom name
/// If neither flags are present, returns the default hardcoded network name.
fn get_testnet_dir(cli_args: &ArgMatches) -> String {
if let Some(testnet_name) = cli_args.value_of("testnet") {
return testnet_name.to_string();
} else if cli_args.value_of("testnet-dir").is_some() {
return CUSTOM_TESTNET_DIR.to_string();
} else {
return eth2_testnet_config::DEFAULT_HARDCODED_TESTNET.to_string();
}
}

/// Try to parse the eth2 testnet config from the `testnet`, `testnet-dir` flags in that order.
/// Returns the default hardcoded testnet if neither flags are set.
pub fn get_eth2_testnet_config<E: EthSpec>(
Expand Down
18 changes: 18 additions & 0 deletions common/clap_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub const BAD_TESTNET_DIR_MESSAGE: &str = "The hard-coded testnet directory was
or when there is no default public network to connect to. \
During these times you must specify a --testnet-dir.";

/// Base directory name for unnamed testnets passed through the --testnet-dir flag
pub const CUSTOM_TESTNET_DIR: &str = "custom";

/// Attempts to load the testnet dir at the path if `name` is in `matches`, returning an error if
/// the path cannot be found or the testnet dir is invalid.
pub fn parse_testnet_dir<E: EthSpec>(
Expand All @@ -34,6 +37,21 @@ pub fn parse_hardcoded_network<E: EthSpec>(
Eth2TestnetConfig::constant(network_name.as_str())
}

/// Gets the testnet directory name
///
/// Tries to get the name first from the "testnet" flag,
/// if not present, then checks the "testnet-dir" flag and returns a custom name
/// If neither flags are present, returns the default hardcoded network name.
pub fn get_testnet_dir(matches: &ArgMatches) -> String {
if let Some(testnet_name) = matches.value_of("testnet") {
return testnet_name.to_string();
} else if matches.value_of("testnet-dir").is_some() {
return CUSTOM_TESTNET_DIR.to_string();
} else {
return eth2_testnet_config::DEFAULT_HARDCODED_TESTNET.to_string();
}
}

/// If `name` is in `matches`, parses the value as a path. Otherwise, attempts to find the user's
/// home directory and appends `default` to it.
pub fn parse_path_with_default_in_home_dir(
Expand Down

0 comments on commit 53892af

Please sign in to comment.