From f91ef2963e4da79dccbcc11e4fb1792f6b857107 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Wed, 12 Jul 2023 13:45:42 +0200 Subject: [PATCH] cli: Fix partial matching for the --seed flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit addresses the inconsistent parsing of the command by fixing the partial matching behavior for the `--seed` flag. Previously, specifying the seed value resulted in an invalid option error, as shown in the example below: ``` ➜ ~ rad sync --seed z6MksmpU5b1dS7oaqF2bHXhQi1DWy2hB7Mh9CuN7y1DN6QSz ✗ Error: rad sync: invalid option '--seed' ``` With this fix, there are no restrictions on when the seed can be specified. In a future change, we plan to implement a custom error message when a match case does not meet specific requirements, such as `rad --fetch --announce`, which will return a more informative error message. However, this enhancement is left for a derived solution. ``` ➜ ~ rad sync --fetch --announce ✗ Error: rad sync: invalid option '--announce' ``` Fixes: d6cebf613f Suggested-by: Slack Coder Signed-off-by: Vincenzo Palazzo --- radicle-cli/src/commands/sync.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/radicle-cli/src/commands/sync.rs b/radicle-cli/src/commands/sync.rs index 2ffdc601..d0b1141f 100644 --- a/radicle-cli/src/commands/sync.rs +++ b/radicle-cli/src/commands/sync.rs @@ -79,7 +79,7 @@ impl Args for Options { Long("verbose") | Short('v') => { verbose = true; } - Long("seed") if matches!(mode, SyncMode::Fetch) => { + Long("seed") => { let val = parser.value()?; let val = term::args::nid(&val)?; seed = Some(val); @@ -108,6 +108,10 @@ impl Args for Options { } } + if seed.is_some() && mode != SyncMode::Fetch { + anyhow::bail!("`--seed` must be used with `--fetch`"); + } + Ok(( Options { rid,