Avoid using clap deprecated features #787
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.
The PR will fix #786 .
πͺ Motivation
In order to minimize future security risks and maintain ease of use, it is recommended to avoid using deprecated features of clap.
β What I did
I have refactored the code so that no warning appears when the following command is executed:
This command was introduced for migration to v4, but we can use it here.
π Main Changes
also see π : https://github.com/clap-rs/clap/blob/master/CHANGELOG.md
in
app.rs
...App
->Command
App
is just an alias ofCommand
in this version, so we can replace it.Arg::action
ArgAction::Append
instead ofArg::take_value
ArgAction::SetTrue
for bool flags (likelsd -a
)Arg::validator
->Arg::value_parser
Ok(validated_value)
.Fn(&str) -> Result<T, E>
pattern.)in
flags/*.rs
...Command::get_matches_from_safe
->Command::try_get_matches_from
Command::get_matches_from_safe
is just an alias ofCommand::try_get_matches_from
, so we can replace it.ArgMatches::is_present
->ArgMatches::get_one::<bool>
ArgMatches::occurrences_of(id) > 0
->ArgMatches::value_source(id) == ValueSource::CommandLine
ArgMatches::occurrences_of(id)
returns the number of times an argument was used at runtime, so we can replace it withValueSource::CommandLine
check.ArgMatches::values_of
->ArgMatches::get_many::<T>
ArgMatches::value_of
->ArgMatches::get_one::<T>
ArgMatches::get_*::<String>
and thenmap(String::as_str)
to conform to existing codes which uses&str
.π Comments
TODO
cargo fmt
Update default config/theme in README (if applicable)Update man page at lsd/doc/lsd.md (if applicable)