You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
Currently, clap's API is focused on the CLI domain, with data being tracked as OsString with specialized helpers for String. At the tale-end of the builder API, we provide the value_of_t API. We do gloss over this in the derive API.
Problems with the current approach
Bloat of functions in ArgMatches to handle every case
Derive API parses data twice, once as part of validation and then when giving it to the user (#2206)
Most builder users won't bother with the extra development effort of validating like the derive API and instead will not get first class clap errors for their parse errors
Change the data structure for ArgMatches to store Box<Any + Send + Sync + 'static>
Add a generic getter, gated behind a feature flag
Add a builder function for setting a custom value, gated behind a feature flag
Change the default parser from OsString to String, deprecating AllowInvalidUtf8, gated behind a feature flag
Mark old API deprecated, gated behind a feature flag
On next breaking release, remove deprecated APIs and remove feature gates
Other considerations / open questions
For multiple_values, users also have to set default_values, value_names, and value_hints, should we follow possible_values and avoid users passing in parallel arrays?
How do we handle default values?
Users will want to set their defaults according to their application data type
To show a default in help, we need it to be Display
How many feature gates and when do we remove them?
The sooner its public, the better, for collecting feedback
The more people using it, the more impacted by subtle behavior changes (default parser)
We could put in hacks to make the old API work along side the new API and set the default parser according to AllowInvalidUtf8
How do we handle optional vs required, especially in light of #2505?
We have to deal with present / not-present, invalid cast of Any, etc.
For the parser, how do we balance flexibility and performance
We could make the parser a trait ValueParser and provide a struct BoxedValueParser that contains an enum for common function-pointer signatures (wrapped with converters for the error types) and people can explicitly construct a BoxedValueParser for their custom type
In designing the API, we should keep in mind that people are also wanting access to what authored a value (env, default, CLI) (TODO Find Issue)
Unsure how this feature would even fit into clap_derive
Long term, we will want to morph the ArgMatches API to be more map-like
#1206
Having a remove function would allow clap_derive to move values, instead of clone them.
Long term, we need to consider other type-related features besides default_value:
ValueHint: if we can detect and set a default for Path that would provide a better default experience
value_name for named arguments: the default (of --name <name>) is redundant. If we could provide type related defaults (e.g. PATH for PathBuf, NUM for numbers), it would also provide a better default experience
@pksunkara just captured in the Issue my thoughts from not being able to sleep last night :) I'm sure you also have some and would love to hear and see how we can synthesize the two.
The only linked issue I'm seeing this directly help with is #2206. I thought it would help with #2505 but it sounds like we just repeat the same problem after exploring the idea.
Comment by pksunkara Monday Oct 18, 2021 at 22:55 GMT
Looks good to me. I would actually make this the main product objective for 4.0. I will add more if needed once I get into this context later (which I still have in my todo)
Hmm. My main concern there is that this line looks like it could easily become a footgun if not handled carefully:
Change the default parser from OsString to String, deprecating AllowInvalidUtf8, gated behind a feature flag.
Windows may make it difficult to get paths with un-paired surrogates, but I've found mojibake'd filenames to be easy on POSIX platforms... to the point where it led me to report a bug in Serde because a mojibake'd Japanese ID3 tag had put mojibake'd characters in media file names during auto-renaming and Serde doesn't complain if you want to put a PathBuf into a JSON file without explicitly specifying how to handle un-UTF8-able contents. (Was it ID3v1 that left the tag's encoding to be communicated out-of-band? I think Audacious Media Player actually has a browser-style encoding detector for that.)
Hmm. My main concern there is that this line looks like it could easily become a footgun if not handled carefully:
With the proposed API, if you want a path, you'd be specifying it as a PathBuf and we would parse from OsStr. Just if you didn't specify any custom type, we'd be choosing String by default which seems to be what people want in most cases.
Comment by ssokolow Friday Nov 05, 2021 at 17:05 GMT
Ahh. By "if not handled carefully", I meant "this could turn into a footgun for end users if clap doesn't handle it carefully", and that should fit the definition of "clap handling it carefully" well enough.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Issue by pksunkara
Friday Aug 13, 2021 at 01:05 GMT
Originally opened as clap-rs/clap#2683
Currently, clap's API is focused on the CLI domain, with data being tracked as
OsString
with specialized helpers forString
. At the tale-end of the builder API, we provide thevalue_of_t
API. We do gloss over this in the derive API.Problems with the current approach
ArgMatches
to handle every case_os
functions but disallow non-UTF8 during validation (fix: Provide path to avoid UTF-8 panics clap-rs/clap#2677)See also clap-rs/clap#2832
Roll out
ArgMatches
to storeBox<Any + Send + Sync + 'static>
OsString
toString
, deprecatingAllowInvalidUtf8
, gated behind a feature flagOther considerations / open questions
multiple_values
, users also have to setdefault_values
,value_names
, andvalue_hints
, should we followpossible_values
and avoid users passing in parallel arrays?Display
clap_derive
currently punts on this by providing both adefault_value
anddefault_value_t
where the latter has to supportDisplay
and it gets forwarded todefault_value
, see feat(derive): Specify defaults by native expressions clap-rs/clap#2635AllowInvalidUtf8
Any
, etc.trait ValueParser
and provide astruct BoxedValueParser
that contains an enum for common function-pointer signatures (wrapped with converters for the error types) and people can explicitly construct aBoxedValueParser
for their custom typeclap_derive
ArgMatches
API to be more map-likeremove
function would allowclap_derive
to move values, instead of clone them.default_value
:ValueHint
: if we can detect and set a default forPath
that would provide a better default experiencevalue_name
for named arguments: the default (of--name <name>
) is redundant. If we could provide type related defaults (e.g.PATH
forPathBuf
,NUM
for numbers), it would also provide a better default experienceOriginal
Basically, there are two things that need to be solved here.
I have to dig into the code to write a longer description of issues with the current behaviour and design.
See also clap-rs/clap#2832
The text was updated successfully, but these errors were encountered: