From 567751f03859baa125af24c6ffcda0e66ca65701 Mon Sep 17 00:00:00 2001 From: Martin Kysel Date: Mon, 16 Dec 2024 14:21:00 -0500 Subject: [PATCH] Minor XDGB edge cases (#1425) This fixes 3 minor issues: 1) when the user does not specify a subcommand XDBG exits with code 0. This can be a bit confusing. Print help instead and exit with an error. - I am open to other options. Printing to stderr and std::process:exit(1) are also pretty good choices. 2) Generate could not print help ``` $ cargo run --package xdbg -- generate -h Finished `dev` profile [unoptimized] target(s) in 0.19s Running `target/debug/xdbg generate -h` The application panicked (crashed). Message: Command generate: Short option names must be unique for each argument, but '-i' is in use by both 'invite' and 'interval' Location: /Users/martinkysel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_builder-4.5.23/src/builder/debug_asserts.rs:112 ``` Now it can 3) Typo in `loclalhosltls` --- xmtp_debug/src/app.rs | 6 ++++++ xmtp_debug/src/args.rs | 2 +- xmtp_debug/src/constants.rs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xmtp_debug/src/app.rs b/xmtp_debug/src/app.rs index 79f6c6473..5dcd4e810 100644 --- a/xmtp_debug/src/app.rs +++ b/xmtp_debug/src/app.rs @@ -21,6 +21,7 @@ mod store; /// Types shared between App Functions mod types; +use clap::CommandFactory; use color_eyre::eyre::{self, Result}; use directories::ProjectDirs; use std::{fs, path::PathBuf, sync::Arc}; @@ -95,6 +96,11 @@ impl App { } = opts; debug!(fdlimit = get_fdlimit()); + if cmd.is_none() && !clear { + AppOpts::command().print_help()?; + eyre::bail!("No subcommand was specified"); + } + if let Some(cmd) = cmd { match cmd { Generate(g) => generate::Generate::new(g, backend, db).run().await, diff --git a/xmtp_debug/src/args.rs b/xmtp_debug/src/args.rs index ec1decbaf..3c2cf67c5 100644 --- a/xmtp_debug/src/args.rs +++ b/xmtp_debug/src/args.rs @@ -57,7 +57,7 @@ pub struct Generate { #[arg(long, short)] pub amount: usize, /// Specify amount of random identities to invite to group - #[arg(long, short)] + #[arg(long)] pub invite: Option, #[command(flatten)] pub message_opts: MessageGenerateOpts, diff --git a/xmtp_debug/src/constants.rs b/xmtp_debug/src/constants.rs index 93205e2e5..d8bd69bb3 100644 --- a/xmtp_debug/src/constants.rs +++ b/xmtp_debug/src/constants.rs @@ -14,7 +14,7 @@ pub static XMTP_PRODUCTION_D14N: LazyLock = LazyLock::new(|| Url::parse("") pub static XMTP_DEV_D14N: LazyLock = LazyLock::new(|| Url::parse("https://grpc.testnet.xmtp.network:443").unwrap()); pub static XMTP_LOCAL_D14N: LazyLock = - LazyLock::new(|| Url::parse("http://localhots:5050").unwrap()); + LazyLock::new(|| Url::parse("http://localhost:5050").unwrap()); pub static XMTP_PRODUCTION_PAYER: LazyLock = LazyLock::new(|| Url::parse("").unwrap()); pub static XMTP_DEV_PAYER: LazyLock =