-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
argparse builtin: Replacement / enhancement for getopts #469
Comments
What's the rationale for |
I guess there are three possibilities, all of which are used in some tools.
I think Oil and Go's way reduces unnecessary variation, which improves readability. You have to type a tiny bit more, which I think is OK.
|
In Next Generation Shell, I decided that if It is similar to how Perl6 parses command line arguents. The difference is that NGS looks at defined multi-method and tries to parse according to specified parameters as opposed to Perl6 which first parses command line arguments (configurable via I do think it's very convenient approach and should be considered in case of Oil too. From script that I wrote today:
|
The sh on Solaris has a nice extension to getopts that allows for describing long args in the optstring. Bascially, to describe a long arg fast for f, you write f(fast). It naturally works with old getopts code, and for older shells you should be able to write a paren-stripping wrapper for it. As for the -abc thing… I don't like how Go does that, but fine I guess. After all nobody is typing on the old finger-breaking heavy mechanical keyboards anymore. Still, the old (Unix) style shorthand can be made deterministic once an optstring is given, so maybe it's worth a try? |
This is very important, but users can also fill it in themselves with the more powerful Oil language, so removing "essential" label |
I realized that Hay made some progress on custom commands in a block, like https://oilshell.zulipchat.com/#narrow/stream/264891-oil-help/topic/getopts.20alternative.3F |
I would allow different flavors for My suggestions would be an additional command like If we want one right way for parsing parameters we have to be flexible, otherwise some stubborn person will write its own implementation which parses it differently and people will find reasons two parsers aren't enough, etc. |
FWIW I removed the Go style flag parsing in Oil awhile ago ! It was not compatible with existing builtins, so we had an awkward split between OSH and Oil builtins Now all builtins are for OSH AND Oil, which is simpler So it's possible to have both styles but it will almost certainly lean toward the current Oil / GNU style, not Go style |
Summary of Enhancements to Oil
That's it? Anything else? |
From #297 :
I'd like to point out what seems to make a significant difference to me, compared to a testing framwork. Of course argparse would need to support a rich interface to be able to define fully customized CLIs. However, hopefully you also realized a modern language should also be able provide a basic CLI interface for any script, out of the box, without needing any definition at all. (In the absence of custom interface definition/disabling.) This can even work for GUIs. (Useful errors/infos/defaults would even make these features self-discoverable, e.g. Examples, that show this "sane user interface by default" kind of thing: |
Hm yeah Raku does something like those I do think the "Python-like parameters vs. shell-like flags" is going to be a design issue, it's really a special case of "procs vs. funcs" I think my inclination is to keep things more shell-like, or at least have shell-like "fallbacks", but people coming from other languages may have problems with that |
On the script calling side I'd say providing the shell-like features like "stackable" flags is the right thing for an interactive shell. Good part of what gives the command prompt it's terse magic are the shorthands, e.g. |
Now I found it, again: On the shell (function) coding side, this could be an example of generating UI even for plain shell vars and functions (OSH): https://github.com/TangoMan75/shoe Edited: |
As the shoe example works based on a naming convention, maybe alternatively also think of using a convention to explicitly expose vars/functions to the UI, instead of to make them private/hiden. Which way might be preferable? |
Support for subcommands with different flags and args would be nice as well. |
Would this be enough:
Not sure if, or how, this could be extended to further sub-command levels. sub-functions? |
For example, a naming convention:
|
Turned out that with the typed arg definitions for procs, and especially named-args, proc args can very naturally map to CLI options: #1837 That could very much reduce all necessary configuring to only deviations from the defaults. (Possibly all in the proc definition and docstring? So defaults do not require having any formal getopts specification.) |
In other words: Let [proc] option args be defined in such a programmatically and syntactically natural way, that the common external command interface that includes flags and options ("external narrow waist") can also be used as internal interface to calling procs ("internal narrow waist"). Consider parsing flags and options to procs as typed named-args (i.e. optional if defined with a default). |
We need something much better for the Oil language. It's silly that it's hard to write decent command line tools in shell!
-abc
is one flag, not a shortcut for-a -b -c
)--help
for youMore:
Could look something like this:
That's roughly the API for Python's argparse but in a more compact format.
The text was updated successfully, but these errors were encountered: