Skip to content

Commit 23098c4

Browse files
dom-niejclapis
andauthored
Fix broken CLI caused by double-parse bug (#428)
Co-authored-by: Joe Clapis <[email protected]>
1 parent e50b8d2 commit 23098c4

4 files changed

Lines changed: 24 additions & 43 deletions

File tree

bin/cli.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
use clap::Parser;
22

3-
/// Version string with a leading 'v'
4-
const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));
5-
6-
/// Subcommands and global arguments for the module
7-
#[derive(Parser, Debug)]
8-
#[command(name = "Commit-Boost CLI", version = VERSION, about, long_about = None)]
9-
struct Cli {}
10-
11-
/// Main entry point of the Commit-Boost CLI
123
#[tokio::main]
134
async fn main() -> eyre::Result<()> {
14-
// Parse the CLI arguments (currently only used for version info, more can be
15-
// added later)
16-
let _cli = Cli::parse();
17-
185
color_eyre::install()?;
19-
// set default backtrace unless provided
206

217
let args = cb_cli::Args::parse();
228

bin/pbs.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,14 @@ use clap::Parser;
77
use eyre::Result;
88
use tracing::{error, info};
99

10-
/// Version string with a leading 'v'
11-
const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));
12-
13-
/// Subcommands and global arguments for the module
14-
#[derive(Parser, Debug)]
15-
#[command(name = "Commit-Boost PBS Service", version = VERSION, about, long_about = None)]
16-
struct Cli {}
17-
1810
#[tokio::main]
1911
async fn main() -> Result<()> {
20-
// Parse the CLI arguments (currently only used for version info, more can be
21-
// added later)
22-
let _cli = Cli::parse();
12+
let _args = cb_cli::PbsArgs::parse();
2313

2414
color_eyre::install()?;
2515

2616
let _guard = initialize_tracing_log(PBS_MODULE_NAME, LogsSettings::from_env_config()?);
2717

28-
let _args = cb_cli::PbsArgs::parse();
29-
3018
let (pbs_config, config_path) = load_pbs_config(None).await?;
3119

3220
PbsService::init_metrics(pbs_config.chain)?;

bin/signer.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,14 @@ use clap::Parser;
77
use eyre::Result;
88
use tracing::{error, info};
99

10-
/// Version string with a leading 'v'
11-
const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));
12-
13-
/// Subcommands and global arguments for the module
14-
#[derive(Parser, Debug)]
15-
#[command(name = "Commit-Boost Signer Service", version = VERSION, about, long_about = None)]
16-
struct Cli {}
17-
1810
#[tokio::main]
1911
async fn main() -> Result<()> {
20-
// Parse the CLI arguments (currently only used for version info, more can be
21-
// added later)
22-
let _cli = Cli::parse();
12+
let _args = cb_cli::SignerArgs::parse();
2313

2414
color_eyre::install()?;
2515

2616
let _guard = initialize_tracing_log(SIGNER_MODULE_NAME, LogsSettings::from_env_config()?);
2717

28-
let _args = cb_cli::SignerArgs::parse();
29-
3018
let config = StartSignerConfig::load_from_env()?;
3119
let server = SigningService::run(config);
3220

crates/cli/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ use clap::{Parser, Subcommand};
55

66
mod docker_init;
77

8+
/// Version string with a leading 'v'
9+
const VERSION: &str = concat!("v", env!("CARGO_PKG_VERSION"));
10+
811
#[derive(Parser, Debug)]
9-
#[command(version, about, long_about = LONG_ABOUT, name = "commit-boost-cli")]
12+
#[command(version = VERSION, about, long_about = LONG_ABOUT, name = "commit-boost-cli")]
1013
pub struct Args {
1114
#[command(subcommand)]
1215
pub cmd: Command,
@@ -41,9 +44,25 @@ impl Args {
4144
const LONG_ABOUT: &str = "Commit-Boost allows Ethereum validators to safely run MEV-Boost and community-built commitment protocols";
4245

4346
#[derive(Parser, Debug)]
44-
#[command(version, about, long_about = LONG_ABOUT, name = "commit-boost-pbs")]
47+
#[command(version = VERSION, about, long_about = LONG_ABOUT, name = "commit-boost-pbs")]
4548
pub struct PbsArgs;
4649

4750
#[derive(Parser, Debug)]
48-
#[command(version, about, long_about = LONG_ABOUT, name = "commit-boost-signer")]
51+
#[command(version = VERSION, about, long_about = LONG_ABOUT, name = "commit-boost-signer")]
4952
pub struct SignerArgs;
53+
54+
#[cfg(test)]
55+
mod tests {
56+
use super::*;
57+
58+
#[test]
59+
fn version_has_v_prefix() {
60+
assert!(VERSION.starts_with('v'), "VERSION should start with 'v', got: {VERSION}");
61+
}
62+
63+
#[test]
64+
fn parse_init_subcommand() {
65+
Args::try_parse_from(["commit-boost-cli", "init", "--config", "/tmp/config.toml"])
66+
.expect("should parse init subcommand");
67+
}
68+
}

0 commit comments

Comments
 (0)