Optimism Cli struct (#9416)

This commit is contained in:
Luca Provini
2024-07-10 15:57:27 +02:00
committed by GitHub
parent 47c038201a
commit 169a4bd536
4 changed files with 125 additions and 3 deletions

View File

@ -10,8 +10,79 @@
// The `optimism` feature must be enabled to use this crate.
#![cfg(feature = "optimism")]
use chainspec::OpChainSpecParser;
use clap::{command, value_parser, Parser};
use commands::Commands;
use reth_chainspec::ChainSpec;
use reth_cli::chainspec::ChainSpecParser;
use reth_cli_commands::node::NoArgs;
use reth_node_core::{
args::{utils::chain_help, LogArgs},
version::{LONG_VERSION, SHORT_VERSION},
};
use std::{ffi::OsString, fmt, sync::Arc};
/// Optimism chain specification parser.
pub mod chainspec;
/// Optimism CLI commands.
pub mod commands;
pub use commands::{import::ImportOpCommand, import_receipts::ImportReceiptsOpCommand};
/// The main reth cli interface.
///
/// This is the entrypoint to the executable.
#[derive(Debug, Parser)]
#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)]
pub struct Cli<Ext: clap::Args + fmt::Debug = NoArgs> {
/// The command to run
#[command(subcommand)]
command: Commands<Ext>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
#[arg(
long,
value_name = "CHAIN_OR_PATH",
long_help = chain_help(),
default_value = OpChainSpecParser::SUPPORTED_CHAINS[0],
value_parser = OpChainSpecParser::default(),
global = true,
)]
chain: Arc<ChainSpec>,
/// Add a new instance of a node.
///
/// Configures the ports of the node to avoid conflicts with the defaults.
/// This is useful for running multiple nodes on the same machine.
///
/// Max number of instances is 200. It is chosen in a way so that it's not possible to have
/// port numbers that conflict with each other.
///
/// Changes to the following port numbers:
/// - `DISCOVERY_PORT`: default + `instance` - 1
/// - `AUTH_PORT`: default + `instance` * 100 - 100
/// - `HTTP_RPC_PORT`: default - `instance` + 1
/// - `WS_RPC_PORT`: default + `instance` * 2 - 2
#[arg(long, value_name = "INSTANCE", global = true, default_value_t = 1, value_parser = value_parser!(u16).range(..=200))]
instance: u16,
#[command(flatten)]
logs: LogArgs,
}
impl Cli {
/// Parsers only the default CLI arguments
pub fn parse_args() -> Self {
Self::parse()
}
/// Parsers only the default CLI arguments from the given iterator
pub fn try_parse_args_from<I, T>(itr: I) -> Result<Self, clap::error::Error>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
Self::try_parse_from(itr)
}
}