-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade clap from 3.1 to 4.0 #2236
Comments
@kalil-pelissier i can help this |
@0xkelvin awesome! assinign the ticket to you! |
@0xkelvin I have no time to work on it at the moment so it's ok for me! |
I am interested in collaborating with someone on their project so I can learn the language while they get a sidekick. |
let me see can we pair-working on this, i still working on it, a bit slow because busy with full time job @EliKalter connect me to discord : 0xqwert#2911 |
@0xkelvin I think you have a mix up, I am not a code owner nor am I a moderator |
@EliKalter I don't think there is any mix up. @0xkelvin is working on this, and you offered your help 2 weeks ago. |
It seems like someone sent a PR for this? |
@0xkelvin said "connect me to discord", I can't connect him to anything, |
oh, i was too slow, let me learn from it as well |
closed by #3209 |
Upgrade clap version from 3.1 to 4.0
Changelog
Sourced from clap changelog.
[4.0.0] - 2022-09-28
Highlights
Arg::num_args(range)
Clap has had several ways for controlling how many values will be captured without always being clear on how they interacted, including
Arg::multiple_values(true)
Arg::number_of_values(4)
Arg::min_values(2)
Arg::max_values(20)
Arg::takes_value(true)
These have now all been collapsed into
Arg::num_args
which accepts bothsingle values and ranges of values.
num_args
controls how many raw argumentson the command line will be captured as values per occurrence and independent
of value delimiters.
See Issue 2688 for more background.
Polishing Help
Clap strives to give a polished CLI experience out of the box with little
ceremony. With some feedback that has accumulated over time, we took this
release as an opportunity to re-evaluate our
--help
output to make sure it ismeeting that goal.
In doing this evaluation, we wanted to keep in mind:
Before:
After:
--version
is available for showing the same thing (if the program has a version set)In talking to users, we found some that liked clap's
man
-like experience.When deviating from this, we are making the assumption that those are more
power users and that the majority of users wouldn't look as favorably on being
consistent with
man
.See Issue 4132 for more background.
More Dynamicism
Clap's API has focused on
&str
for performance but this can makedealing with owned data difficult, like
#[arg(default_value_t)]
generating aString from the default value.
Additionally, to avoid
ArgMatches
from borrowing (and for some features wedecided to forgo), clap took the
&str
argument IDs and hashed them. Thisprevented us from providing a usable API for iterating over existing arguments.
Now clap has switched to a string newtype that gives us the flexibility to
decide whether to use
&'static str
,Cow<'static, str>
for fast dynamic behavior, orBox<str>
for dynamic behavior with small binary size.As an extension of that work, you can now call
ArgMatches::ids
to iterateover the arguments and groups that were found when parsing. The newtype
Id
was used to prevent some classes of bugs and to make it easier to understand
when opaque Ids are used vs user-visible strings.
Clearing Out Deprecations
Instead of doing all development on clap 4.0.0, we implemented a lot of new features during clap 3's development, deprecating the old API while introducing the new API, including:
ArgAction
ValueParser
APIPathBuf
(allowing invalid UTF-8)AppSettings
andArgSettings
enums with getters/settersMigrating
Steps:
-h
and--help
output at a minimum (recommendation: trycmd for snapshot testing)arg.action(ArgAction::...)
on each argument (StoreValue
for options andIncOccurrences
for flags)cargo check --features clap/deprecated
and resolve all deprecation warningsdefault-features = false
, runcargo add clap -F help,usage,error-context
cargo add clap -F wrap_help
unless you want to hard code line wrapsExample test (derive):
Example test (builder):
Note: the idiomatic / recommended way of specifying different types of args in the Builder API has changed:
Before
After:
In particular,
num_args
(the replacement fortakes_value
) will default appropriatelyfrom the
ArgAction
and generally only needs to be set explicitly for theother
num_args
use cases.Breaking Changes
Subtle changes (i.e. compiler won't catch):
arg!
now sets one of (Bump tantivy version. #3795):ArgAction::SetTrue
, requiringArgMatches::get_flag
instead ofArgMatches::is_present
ArgAction::Count
, requiringArgMatches::get_count
instead ofArgMatches::occurrences_of
ArgAction::Set
, requiringArgMatches::get_one
instead ofArgMatches::value_of
ArgAction::Append
, requiringArgMatches::get_many
instead ofArgMatches::values_of
ArgAction::Set
,ArgAction::SetTrue
, andArg::Action::SetFalse
nowconflict by default to be like
ArgAction::StoreValue
andArgAction::IncOccurrences
, requiringcmd.args_override_self(true)
to override instead (Bump colored from 2.0.4 to 2.1.0 in /quickwit #4261)Arg
s default action isArgAction::Set
, rather thanArgAction::IncOccurrence
to reduce confusing magic through consistency (Store instrumentation scope #2687, Ensures the load of pipelines does not exceed 80%. #4032, see also Bump urllib3 from 2.0.4 to 2.0.7 in /quickwit/rest-api-tests #3977)mut_arg
can no longer be used to customize help and version arguments, instead disable them (Command::disable_help_flag
,Command::disable_version_flag
) and provide your own (Spec and Implement the end of life of a shard. #4056)Command
,Arg
,ArgGroup
, andPossibleValue
, assuming'static
.string
feature flag will enable support forString
s (Put the index-uri parameter in the IndexConfig #1041, ConsiderActorExitStatus::Quit
as a successful exit? #2150, Issue/4184 assign shard logic #4223)arg!(--flag <value>)
is now optional, instead of required. Add.required(true)
at the end to restore the original behavior (Update to latest version ofrust-rdkafka
and remove consumer poll loop #4206)help
,usage
anderror-context
, requiring adding them back in ifdefault-features = false
(Add native support for Google Storage #4236)""
argument for external subcommands to make it easier to distinguish them from built-in commands (Add support for ES exists query #3263)Arg::allow_hyphen_values
, to be consistent withCommand::allow_hyphen_values
(Add the index ID and source ID in the warn logs #4187)Arg::value_terminator
must be its own argument on the CLI rather than being in a delimited list (Improve behavior on corrupted checkpoint. #4025)wrap_help
feature flag, either enable it or hard code your wraps (Instrument routers and ingesters #4258)DeriveDisplayOrder
the default and removed the setting. To sort help, setnext_display_order(None)
(Tracing: store trace and span IDs as byte fields #2808)Command::next_display_order
instead ofDeriveDisplayOrder
and using its own initial display order value (Tracing: store trace and span IDs as byte fields #2808)Command::help_template
(The ES compatible API accepts malformed requests #4132)Command::help_template
,Arg::help_heading
, andCommand::subcommand_help_heading
(The ES compatible API accepts malformed requests #4132)COMMAND
for the value name. To get the old behavior, seeCommand::subcommand_help_heading
andArg::subcommand_value_name
(The ES compatible API accepts malformed requests #4132, Backward compatibilty tests #4155)Command::help_template
. (The ES compatible API accepts malformed requests #4132, (Minor fixes and improvements) Update README.md #4160)--help
and--version
like anyArgAction::SetTrue
flag (Normalize Error Messages #3776)Arg::id
asverbatim
casing, requiring updating of string references to other args like inconflicts_with
orrequires
(Increase default bucket limit? #3282)ValueEnum
variants will now show up in--help
([Tracing] Span status is not indexed #3312)Args
, andArgGroup
is created using the type's name, reserving it for future use (Bump tokio from 1.23.0 to 1.24.0 in /quickwit #2621, Bump openssl from 0.10.59 to 0.10.60 in /quickwit #4209)next_help_heading
can now leak out of a#[clap(flatten)]
, like all other command settings (Bump @adobe/css-tools from 4.3.1 to 4.3.2 in /quickwit/quickwit-ui #4222)Easier to catch changes:
ArgMatches
now returns the argId
s, rather than the values to reduce overhead and offer more flexibility. (Keyword repeat #4072)Arg::number_of_values
(average-across-occurrences) toArg::num_args
(per-occurrence) (raw CLI args, not parsed values) (Tracing: use pagination for queries fetching a huge number of spans #2688, Ingester close shards gRPC #4023)num_args(0)
no longer impliestakes_value(true).multiple_values(true)
(Ingester close shards gRPC #4023)num_args(1)
no longer impliesmultiple_values(true)
(Ingester close shards gRPC #4023)Arg::min_values
(across all occurrences) withArg::num_args(N..)
(per occurrence) to reduce confusion over different value count APIs (Ingester close shards gRPC #4023)Arg::max_values
(across all occurrences) withArg::num_args(1..=M)
(per occurrence) to reduce confusion over different value count APIs (Ingester close shards gRPC #4023)Arg::multiple_values(true)
withArg::num_args(1..)
andArg::multiple_values(false)
withArg::num_args(0)
to reduce confusion over different value count APIs (Ingester close shards gRPC #4023)Arg::takes_value(true)
withArg::num_args(1)
andArg::takes_value(false)
withArg::num_args(0)
to reduce confusion over different value count APIsArg::require_value_delimiter
, either users could useArg::value_delimiter
or implement a custom parser withTypedValueParser
as it was mostly to makemultiple_values(true)
act likemultiple_values(false)
and isn't needed anymore (Exposing pipeline metrics #4026)Arg::new("help")
andArg::new("version")
no longer implicitly disable thebuilt-in flags and be copied to all subcommands, instead disable
the built-in flags (
Command::disable_help_flag
,Command::disable_version_flag
) and mark the custom flags asglobal(true)
. (Spec and Implement the end of life of a shard. #4056)Arg::short('h')
no longer implicitly disables the short flag for help,instead disable
the built-in flags (
Command::disable_help_flag
,Command::disable_version_flag
) provide your ownArg::new("help").long("help").action(ArgAction::Help).global(true)
. (Spec and Implement the end of life of a shard. #4056)ArgAction::SetTrue
andArgAction::SetFalse
now prioritizeArg::default_missing_value
over their standard behavior (Optimize searcher semaphore #4000)Arg::requires_ifs
andArg::default_value*_ifs*
to taking anArgPredicate
, removing ambiguity withNone
when accepting owned and borrowed types (Added support for v2 in the client. #4084)PartialEq
andEq
fromCommand
so we could change external subcommands to use aValueParser
(Support compressed HTTP request bodies in REST API #3990)Arg
,Command
, andArgGroup
calls were switched from accepting&[]
to[]
viaIntoIterator
to be more flexible (Keyword repeat #4072)Arg::short_aliases
and other builder functions that took&[]
need the&
dropped (Bumping quickwit's version to 0.6.5-dev #4081)ErrorKind
andResult
moved into theerror
moduleErrorKind::EmptyValue
replaced withErrorKind::InvalidValue
to remove an unnecessary special case (Refactoring of the CI. #3676, Quickwit doesn't respect URL prefix behind proxy #3968)ErrorKind::UnrecognizedSubcommand
replaced withErrorKind::InvalidSubcommand
to remove an unnecessary special case (Refactoring of the CI. #3676)allow_external_subcommands
fromString
toOsString
as that is less likely to cause bugs in user applications (Support compressed HTTP request bodies in REST API #3990)Command::render_usage
now returns aStyledStr
(Control Plane somehow quits after a few minutes. #4248)parse
tovalue_parser
, removingparse
support (reference blog post in cost section #3827, No messages outputted when indexing malformed json data #3981)#[clap(value_parser)]
and#[clap(action)]
are now redundantsubcommand_required(true).arg_required_else_help(true)
is set instead ofSubcommandRequiredElseHelp
to give more meaningful errors when subcommands are missing and to reduce redundancy (Return an elasticsearch error response for elastic search endpoint #3280)arg_enum
attribute in favor ofvalue_enum
to match the new name (we didn't have support in v3 to mark it deprecated) (Bugfix: truncating the ingest v1 source on initialization. #4127)Arg::default_missing_value
didn't requirenum_args(0..=N)
, now it does (Ingester close shards gRPC #4023)Arg::long
are no longer allowed (revisit parsing of configuration #3691)value_names
thannum_args
(Using rendez-vous hashing to sort nodes used for scheduling. #2695)ArgAction::Version
is used#[track_caller]
s to make it easier to debug assertsoverrides_with
IDs are validoverrides_with
now that Actions replace itmut_arg
receiving an invalid arg ID ormut_subcommand
receiving an invalid command nameCompatibility
MSRV is now 1.60.0
Deprecated
Arg::use_value_delimiter
in favor ofArg::value_delimiter
to avoid having multiple ways of doing the same thingArg::requires_all
in favor ofArg::requires_ifs
now that it takes anArgPredicate
to avoid having multiple ways of doing the same thingArg::number_of_values
in favor ofArg::num_args
to clarify semantic differencesdefault_value_os
,default_values_os
,default_value_if_os
, anddefault_value_ifs_os
as the non_os
variants now accept either astr
or anOsStr
(Remove IndexingStatus from IngestSource #4141)Arg::env_os
in favor ofArg::env
Command::dont_collapse_args_in_usage
is now the default (Takemultilang
feature out ofquickwit-doc-mapper/testsuite
#4151)Command::trailing_var_arg
in favor ofArg::trailing_var_arg
to make it clearer which arg it is meant to apply to (Add the index ID and source ID in the warn logs #4187)Command::allow_hyphen_values
in favor ofArg::allow_hyphen_values
to make it clearer which arg it is meant to apply to (Add the index ID and source ID in the warn logs #4187)Command::allow_negative_numbers
in favor ofArg::allow_negative_numbers
to make it clearer which arg it is meant to apply to (Add the index ID and source ID in the warn logs #4187)Command::write_help
andCommand::write_long_help
in favor ofCommand::render_help
andCommand::render_long_help
(Control Plane somehow quits after a few minutes. #4248)structopt
andclap
attributes in favor of the more specificcommand
,arg
, andvalue
to open the door for more features and clarify relationship to the builder ([Kafka source] Useconsumer.recv()
directly rather thanconsumer.stream()
#1807, Fixed the serialize deserialization of the indexing state to include #4180)#[clap(value_parser)]
and#[clap(action)]
defaulted attributes (its the default) (Bump serde_with from 3.3.0 to 3.4.0 in /quickwit #3976)Behavior Changes
wrap_help
feature, if the terminal size cannot be determined,LINES
andCOLUMNS
variables are used (update tantivy #4186)Features
Arg::num_args
now accepts ranges, allowing setting both the minimum and maximum number of values per occurrence (Tracing: use pagination for queries fetching a huge number of spans #2688, Ingester close shards gRPC #4023)value_parser
s forArgAction::SetTrue
/ArgAction::SetFalse
(Close fetch stream with an error if it does not reach EOF #4092)From<&OsStr>
,From<OsString>
,From<&str>
, andFrom<String>
tovalue_parser!
(Shard load #4257)Command
,Arg
,ArgGroup
,PossibleValue
, etc without managing lifetimes with thestring
feature flag (ConsiderActorExitStatus::Quit
as a successful exit? #2150, Issue/4184 assign shard logic #4223)error-context
,help
andusage
feature flags that can be turned off for smaller binaries (Add native support for Google Storage #4236)StyledStr::ansi()
toDisplay
with ANSI escape codes (Control Plane somehow quits after a few minutes. #4248)Error::apply
for changing the formatter for dropping binary size (Bump axios from 1.5.1 to 1.6.1 in /quickwit/quickwit-ui #4111)Error::render
for formatting the error into aStyledStr
PossibleValue::help
in long help (--help
) ([Tracing] Span status is not indexed #3312){tab}
variable forCommand::help_template
( Add local AGPL license link in LICENSE.md #4161)Command::render_help
andCommand::render_long_help
for formatting the error into aStyledStr
(add documents about multi match and match phrase #3873, Control Plane somehow quits after a few minutes. #4248)Command::render_usage
now returns aStyledStr
(Control Plane somehow quits after a few minutes. #4248)Fixes
required
is not used with conditional required settings (Disable multilang by default. #3660)cmd.allow_invalid_for_utf8_external_subcommands
withcmd.external_subcommand_value_parser
(nitpicks #3733)Arg::default_missing_value
now applies per occurrence rather than if a value is missing across all occurrences (Apply query simplification optimization to find_trace #3998)arg!(--long [value])
to accept0..=1
per occurrence rather than across all occurrences, making it safe to use withArgAction::Append
(Bump node from 18 to 21 #4001)OsStr
s forArg::{required_if_eq,required_if_eq_any,required_if_eq_all}
(Added support for v2 in the client. #4084)wrap_help
feature, if the terminal size cannot be determined,LINES
andCOLUMNS
variables are used (update tantivy #4186)Command::display_name
in the help title rather thanCommand::bin_name
ArgAction::Count
by adding an...
(feat: enable request bodies decompression #4003)cmd help help
(Improve merge performance. #4131)[positional]
in list when relevant (Bound memory and disk usage at the queue level #4144)[positional]
in usage (Takemultilang
feature out ofquickwit-doc-mapper/testsuite
#4151)-h
/--help
when applicable (The ES compatible API accepts malformed requests #4132, Minor fixes & doc #4159)next_line_help
, don't add blank lines (The ES compatible API accepts malformed requests #4132, store split_fields in split #4190)Command::display_name
rather thanCommand::bin_name
(fix sort order in UI #3966)""
argument for external subcommands (Add support for ES exists query #3263)Arg::allow_hyphen_values
, likeCommand::allow_hyphen_values
(Add the index ID and source ID in the warn logs #4187)InvalidSubcommand
overUnknownArgument
in more cases (avoid unneeded copy on touching but non-overlaping byte ranges #4219)Arg::id
asverbatim
casing (Increase default bucket limit? #3282)#[clap(value_parser, action)]
instead of#[clap(parse)]
(reference blog post in cost section #3827)The text was updated successfully, but these errors were encountered: