Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clap derive #3007

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 71 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion account_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
bls = { path = "../crypto/bls" }
clap = "2.33.3"
clap = { version = "3.0.14", features = ["derive"] }
types = { path = "../consensus/types" }
environment = { path = "../lighthouse/environment" }
eth2_network_config = { path = "../common/eth2_network_config" }
Expand All @@ -24,6 +24,8 @@ safe_arith = {path = "../consensus/safe_arith"}
slot_clock = { path = "../common/slot_clock" }
filesystem = { path = "../common/filesystem" }
sensitive_url = { path = "../common/sensitive_url" }
serde = "1.0.116"
serde_derive = "1.0.116"

[dev-dependencies]
tempfile = "3.1.0"
36 changes: 17 additions & 19 deletions account_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,34 @@ mod common;
pub mod validator;
pub mod wallet;

use clap::App;
use clap::ArgMatches;
pub use clap::{IntoApp, Parser, Subcommand};
use clap_utils::GlobalConfig;
use environment::Environment;
use serde::{Deserialize, Serialize};
use types::EthSpec;

pub const CMD: &str = "account_manager";
pub const SECRETS_DIR_FLAG: &str = "secrets-dir";
pub const VALIDATOR_DIR_FLAG: &str = "validator-dir";
pub const WALLETS_DIR_FLAG: &str = "wallets-dir";

pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new(CMD)
.visible_aliases(&["a", "am", "account", CMD])
.about("Utilities for generating and managing Ethereum 2.0 accounts.")
.subcommand(wallet::cli_app())
.subcommand(validator::cli_app())
#[derive(Subcommand, Clone, Deserialize, Serialize, Debug)]
#[clap(rename_all = "snake_case", visible_aliases = &["a", "am", "account"],
about = "Utilities for generating and managing Ethereum 2.0 accounts.")]
pub enum AccountManager {
Wallet(wallet::cli::Wallet),
Validator(validator::cli::Validator),
}

/// Run the account manager, returning an error if the operation did not succeed.
pub fn run<T: EthSpec>(matches: &ArgMatches<'_>, env: Environment<T>) -> Result<(), String> {
match matches.subcommand() {
(wallet::CMD, Some(matches)) => wallet::cli_run(matches)?,
(validator::CMD, Some(matches)) => validator::cli_run(matches, env)?,
(unknown, _) => {
return Err(format!(
"{} is not a valid {} command. See --help.",
unknown, CMD
));
}
pub fn run<T: EthSpec>(
account_manager: &AccountManager,
global_config: &GlobalConfig,
env: Environment<T>,
) -> Result<(), String> {
match account_manager {
AccountManager::Wallet(wallet) => wallet::cli_run(wallet, global_config)?,
AccountManager::Validator(validator) => validator::cli_run(validator, global_config, env)?,
}

Ok(())
}
Loading