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

Migrate account manager cli client to clap derive #6493

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions account_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ account_utils = { workspace = true }
slashing_protection = { workspace = true }
eth2 = { workspace = true }
safe_arith = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
slot_clock = { workspace = true }
filesystem = { workspace = true }
sensitive_url = { workspace = true }
Expand Down
54 changes: 24 additions & 30 deletions account_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ mod common;
pub mod validator;
pub mod wallet;

use clap::Arg;
use clap::ArgAction;
use clap::ArgMatches;
use clap::Command;
use clap_utils::FLAG_HEADER;
use clap::Parser;
use environment::Environment;
use serde::Deserialize;
use serde::Serialize;
use types::EthSpec;

pub const CMD: &str = "account_manager";
Expand All @@ -16,36 +15,31 @@ pub const VALIDATOR_DIR_FLAG: &str = "validator-dir";
pub const VALIDATOR_DIR_FLAG_ALIAS: &str = "validators-dir";
pub const WALLETS_DIR_FLAG: &str = "wallets-dir";

pub fn cli_app() -> Command {
Command::new(CMD)
.visible_aliases(["a", "am", "account"])
.about("Utilities for generating and managing Ethereum 2.0 accounts.")
.display_order(0)
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("Prints help information")
.action(ArgAction::HelpLong)
.display_order(0)
.help_heading(FLAG_HEADER),
)
.subcommand(wallet::cli_app())
.subcommand(validator::cli_app())
#[derive(Clone, Deserialize, Serialize, Debug, Parser)]
#[clap(visible_aliases = &["a", "am", "account"], about = "Utilities for generating and managing Ethereum 2.0 accounts.")]
pub struct AccountManager {
#[clap(subcommand)]
pub subcommand: AccountManagerSubcommand,
}

#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
#[clap(rename_all = "kebab-case")]
pub enum AccountManagerSubcommand {
Wallet(wallet::cli::Wallet),
Validator(validator::cli::Validator),
}

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

Ok(())
Expand Down
Loading
Loading