-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Thoughts on using clap in certain places? #1006
Comments
I am amenable to swapping either
I would like the opinions of other maintainers as well, but if it's faster than |
They're basically the same speed. The parts you handroll when using getopts are largely the same things clap does, and at times less efficient since they're hand rolled. To put it in context, viewing the benches in clap's repo: while parsing a somewhat complex argv (i.e. one with multiple conflicts, requirements, multiple values, options, etc.) takes ~7,000 nanoseconds (0.007 miliseconds) on my machine.
Yes. It allows the consumer to decide if they want to handle only UTF-8 or allow invalid UTF-8 (such as file names).
It's very flexible, and configurable (see the
It respects the order in which values were supplied, and does allow for multiple instances of flags, values, options, etc. It also optionally allows things such as a POSIX style override instead of a hard conflict. I.e. let's say
I'm not sure what you mean?
Yes. clap allows defining both hidden aliases and visisible aliases for flags/options (those with a switch |
I meant Given what you've said, I personally would be willing to accept a pull request replacing |
Ah ok! Those two invocations would produce identical results in clap. |
I am responsible for the Still it would be possible to use |
Ah ok, that's my mistake! And hence why I think there are still places where using clap may not make sense. To clarify clap stores values in order, but not flags/options in order. The notable exception is when overrides are concerned, they're parsed in order and thus allow the last flag/option to "win" so to speak. This is absolutely something that could be added though if there's a large enough reason to justify doing so. |
Ah yeah it's also possible to do like you said use clap for all the validation and such, then once it's necessary just sweep back through the args to get the order which takes nanoseconds so shouldn't be an issue. |
I started to migrate some programs to clap for consistency. Please see the commit logs |
With uutils/uucore#10 and the associated PR to this repo, everything will be using I will close this issue after those PRs are merged. |
it is on going and separate issues have been created. closing |
What are the maintainers thoughts on using
clap
in certain spots? First, let me say that I'm not advocating a wholesale switch toclap
for all things! 😜I'm just curious if the maintainers are open to some PRs where I think the codebase can become more concise. There's also some nice cases where
clap
provides some additional functionality basically for free (such as bash, fish, zsh, or powershell completion file generations, context sensitive error messages, etc.).I've been looking through some of the codebase and there are a decent number of spots where the code is duplicating what
clap
is already doing.As a super simple and short example; implementation of things like
yes
go down to just this:There's some more complex scenarios like
od
which contains the comment:Yet the what is described is exactly how
clap
parses the arguments, i.e. runningod -fvoxw16
is perfectly valid toclap
and parsed in the matches as-f -o -x -v -w=16
, andclap
also respects--
. So the effort is somewhat being duplicated.Doing a few PRs also helps me maintain
clap
as it can point me to additional pain points and what still needs fixing, adding, changing, etc. 😄Also, thanks for this great project, it's super exciting!
The text was updated successfully, but these errors were encountered: