cli: Fix partial matching for the --seed flag

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 <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo 2023-07-12 13:45:42 +02:00 committed by cloudhead
parent f418b5268c
commit f91ef2963e
No known key found for this signature in database
1 changed files with 5 additions and 1 deletions

View File

@ -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,