fix(cli): crash when using --verbosity
option
#1429
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves: #1428
When using
--verbosity
option, Nextclade panicked with error:(in release builds the message can be different due to type mangling)
This is due to particularities of how
value_parser
works inclap
v4, which is a replacement forpossible_values
functionality we used inclap
v3, but which was removed in v4.In Nextclade the
verbosity
filed is of typelog::LevelFilter
. It seemsclap
v4 can read a list of string values passed tovalue_parser
and displays them correctly in the--help
text, but when trying to actually pass one of these values to the--verbosity
arg,clap
would panic with a downcast error somewhere deep inside the library.It's unclear to me why this is now suddenly needed, because
possible_values
worked just fine, but it seems that using an an iterator to theclap
'sPossibleValue
s constructed out ofLevelFilter
instead of strings work. I found this solution here: clap-rs/clap#4264. There are many more issues and discussions in clap repo about that. Maybe there's a better solution.At the same time, I could not resist to clean up our
verbosity.rs
file, because most of the stuff we copied fromclap-verbosity-flag
crate and never actually use. I also use clap'sdefault_value
parameter to set a default value for theverbosity
now, rather than setting a default manually on runtime.