diff --git a/CHANGELOG.md b/CHANGELOG.md index 4240c6514ec..708809ac43f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org). +## [Zebra 1.0.1](https://github.com/ZcashFoundation/zebra/releases/tag/v1.0.1) - 2023-XX-XX + +### Breaking Changes + +- Zebra now detects subcommand name typos on the command-line. If you want to give Zebra a list of tracing filters, use `zebrad start --filters debug,...` ([#7056](https://github.com/ZcashFoundation/zebra/pull/7056)) + + ## [Zebra 1.0.1](https://github.com/ZcashFoundation/zebra/releases/tag/v1.0.1) - 2023-07-03 Zebra's first patch release fixes multiple peer connection security issues and panics. It also significantly reduces Zebra's CPU usage. We recommend that all users upgrade to Zebra 1.0.1 or later. diff --git a/zebrad/src/commands/entry_point.rs b/zebrad/src/commands/entry_point.rs index 5888c0e5ef4..3955dadb35a 100644 --- a/zebrad/src/commands/entry_point.rs +++ b/zebrad/src/commands/entry_point.rs @@ -1,7 +1,5 @@ //! Zebrad EntryPoint -use std::cmp::min; - use abscissa_core::{Command, Configurable, FrameworkError, Runnable}; use clap::Parser; use std::{ffi::OsString, path::PathBuf}; @@ -42,7 +40,7 @@ pub struct EntryPoint { /// Filter strings which override the config file and defaults // This can be applied to the default start command if no subcommand is provided. - #[clap(help = "tracing filters which override the zebrad.toml config")] + #[clap(long, help = "tracing filters which override the zebrad.toml config")] filters: Vec, } @@ -63,28 +61,23 @@ impl EntryPoint { "start" } + /// Checks if the provided arguments include a subcommand + fn should_add_default_subcommand(&self) -> bool { + self.cmd.is_none() + } + /// Process command arguments and insert the default subcommand /// if no subcommand is provided. pub fn process_cli_args(mut args: Vec) -> clap::error::Result> { - // Check if the provided arguments include a subcommand - let should_add_default_subcommand = EntryPoint::try_parse_from(&args)?.cmd.is_none(); + let entry_point = EntryPoint::try_parse_from(&args)?; // Add the default subcommand to args after the top-level args if cmd is None - if should_add_default_subcommand { - // try_parse_from currently produces an error if the first argument is not the binary name, - let mut num_top_level_args = 1; - - // update last_top_level_arg_idx to the number of top-level args - for (idx, arg) in args.iter().enumerate() { - num_top_level_args = match arg.to_str() { - Some("--verbose" | "-v" | "--version" | "-V" | "--help") => idx + 1, - Some("--config" | "-c") => idx + 2, - _ => num_top_level_args, - } + if entry_point.should_add_default_subcommand() { + args.push(EntryPoint::default_cmd_as_str().into()); + // This duplicates the top-level filters args, but the tracing component only checks `StartCmd.filters`. + for filter in entry_point.filters { + args.push(filter.into()) } - - num_top_level_args = min(num_top_level_args, args.len()); - args.insert(num_top_level_args, EntryPoint::default_cmd_as_str().into()); } Ok(args) diff --git a/zebrad/src/commands/tests.rs b/zebrad/src/commands/tests.rs index f87c48b119a..edd019a9022 100644 --- a/zebrad/src/commands/tests.rs +++ b/zebrad/src/commands/tests.rs @@ -16,7 +16,8 @@ fn args_with_subcommand_pass_through() { (true, false, false, vec!["zebrad", "--help"]), (false, true, false, vec!["zebrad", "start"]), (false, true, true, vec!["zebrad", "-v", "start"]), - (false, true, false, vec!["zebrad", "warn"]), + (false, true, false, vec!["zebrad", "--filters", "warn"]), + (true, false, false, vec!["zebrad", "warn"]), (false, true, false, vec!["zebrad", "start", "warn"]), (true, false, false, vec!["zebrad", "help", "warn"]), ];