This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul leader CLI such that flags are grouped by subcommand
- Loading branch information
Showing
4 changed files
with
182 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,58 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::{Parser, ValueEnum, ValueHint}; | ||
use clap::{Args, Parser, Subcommand, ValueHint}; | ||
use paladin::config::Runtime; | ||
|
||
#[derive(Parser)] | ||
pub(crate) struct Cli { | ||
/// The input mode. If `std-io`, the input is read from stdin. If `http`, | ||
/// the input is read from HTTP requests. If `jerigon`, the input is | ||
/// read from the `debug_traceBlockByNumber` and `eth_getBlockByNumber` | ||
/// RPC methods from Jerigon. | ||
#[arg(short, long, value_enum, default_value_t = Mode::StdIo)] | ||
pub(crate) mode: Mode, | ||
/// The port to listen on when using the `http` mode. | ||
#[arg(short, long, default_value_t = 8080)] | ||
pub(crate) port: u16, | ||
/// The directory to which output should be written (`http` mode only). | ||
#[arg(short, long, required_if_eq("mode", "http"), value_hint = ValueHint::DirPath)] | ||
pub(crate) output_dir: Option<PathBuf>, | ||
/// The RPC URL to use when using the `jerigon` mode. | ||
#[arg(long, required_if_eq("mode", "jerigon"), value_hint = ValueHint::Url)] | ||
pub(crate) rpc_url: Option<String>, | ||
/// The block number to use when using the `jerigon` mode. | ||
#[arg(short, long, required_if_eq("mode", "jerigon"))] | ||
pub(crate) block_number: Option<u64>, | ||
/// Specifies the paladin runtime to use. | ||
#[arg(long, short, value_enum, default_value_t = Runtime::Amqp)] | ||
pub(crate) runtime: Runtime, | ||
#[command(subcommand)] | ||
pub(crate) command: Command, | ||
|
||
#[clap(flatten)] | ||
pub(crate) runtime: RuntimeGroup, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
pub(crate) enum Command { | ||
/// Reads input from stdin and writes output to stdout. | ||
Stdio { | ||
/// The previous proof output. | ||
#[arg(long, short = 'f', value_hint = ValueHint::FilePath)] | ||
previous_proof: Option<PathBuf>, | ||
}, | ||
/// Reads input from a Jerigon node and writes output to stdout. | ||
Jerigon { | ||
// The Jerigon RPC URL. | ||
#[arg(long, short = 'u', value_hint = ValueHint::Url)] | ||
rpc_url: String, | ||
/// The block number for which to generate a proof. | ||
#[arg(short, long)] | ||
block_number: u64, | ||
/// The previous proof output. | ||
#[arg(long, short = 'f', value_hint = ValueHint::FilePath)] | ||
previous_proof: Option<PathBuf>, | ||
}, | ||
/// Reads input from HTTP and writes output to a directory. | ||
Http { | ||
/// The port on which to listen. | ||
#[arg(short, long, default_value_t = 8080)] | ||
port: u16, | ||
/// The directory to which output should be written. | ||
#[arg(short, long, value_hint = ValueHint::DirPath)] | ||
output_dir: PathBuf, | ||
}, | ||
} | ||
|
||
#[derive(Args)] | ||
pub(crate) struct RuntimeGroup { | ||
/// Specifies the number of worker threads to spawn (in memory runtime | ||
/// only). | ||
#[arg(long, short)] | ||
pub num_workers: Option<usize>, | ||
/// The previous proof output. | ||
#[arg(long, short = 'f')] | ||
pub previous_proof: Option<PathBuf>, | ||
} | ||
|
||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, ValueEnum, Default)] | ||
pub(crate) enum Mode { | ||
#[default] | ||
StdIo, | ||
Http, | ||
Jerigon, | ||
pub(crate) num_workers: Option<usize>, | ||
/// Specifies the paladin runtime mode. | ||
#[arg(long, short, value_enum, default_value_t = Runtime::Amqp)] | ||
pub(crate) runtime: Runtime, | ||
/// Specifies the URI for the AMQP broker (AMQP runtime only). | ||
#[arg(long, env = "AMQP_URI", value_hint = ValueHint::Url, required_if_eq("runtime", "amqp"))] | ||
pub amqp_uri: Option<String>, | ||
} |
Oops, something went wrong.