Comments (10)
I've updated the comparison table. argh
has the same binary size overhead as pico-args
, but takes 13x times more to compile.
Another difference is that argh
supports help generation, while pico-args
not (intentionally). And pico-args
supports --value=5
format and native OS strings (for Windows file paths).
from argh.
I'd want --value=5
to at least be supported as a build feature. There's a certain set of conventions I expect from a Linux command. Not everything follows them, but I hate it when programs don't and being unable to provide them in my own creations is a deal-breaker. They include:
- Supporting
-abc
as shorthand for-a -b -c
(Whether-abc foo
is equivalent to-a -b -c foo
when-c
takes an argument is more negotiable.) - Supporting
--this
format for long arguments (GNU-style, not X11-style-this
) - Supporting both
--foo=bar
and--foo bar
(It's useful for avoiding certain kinds of quoting-related footguns or needs to switch to much more advanced constructs when writing shell scripts which pass user-specified sets of arguments.) - Supporting both
-h
and--help
for help (I have a zsh script which retrofits-h
onto GNU coreutils.) - Not requiring optional arguments to come before positional arguments (eg.
alias foo="foo --bar baz"; foo --garg --vorticon
) - Generating
--help
output that's compatible with the conventions assumed byhelp2man
- Making an effort to follow existing conventions for command-line argument meanings.
- Allowing later specifications of a non-accumulating argument to override earlier ones. (eg.
alias foo="foo --outfile=bar"; foo --outfile=baz
)
(As you can see, many of the oddities are affordances for making shell-scripting and aliasing more convenient.)
from argh.
Some context,this tool wasn't written for linux, it was written for Fuchsia which has a very different set of constraints. This is called out in the first line of the README. However, we happen to use it quite happily for linux host-side tools these days. I'm not against adding this support because I would like this library to be maximally useful, but it would need to be under a "linux" feature set.
https://fuchsia.dev/fuchsia-src/development/api/cli
from argh.
Maybe it's going to be a premature opinion, but I feel like argh
is the only choice starting from 2020. 👏
What I basically need: I need a prebuilt graph of my subcommands and options (thanks to #[derive]), and then parse command-line arguments accordingly. It should be easy and cheap (buildtime/runtime/binsize). It should have configurable help. Source code of the library should be clear and credible. So you will find it in argh
.
from argh.
--foo bar
vs. --foo=bar
and they have to do with two features of Bourne shell script that become troublesome to get right when you're doing something like this my_script --cmd "foo --arg1 --arg2 bar baz"
(or reading a set of arguments from an environment variable).
- Not quoting enough when nesting things like
""
,''
, and$()
or using too many or too few escapes, because, to make typing things on the command-line comfortable, each statement needs to have its arguments re-quoted to prevent splitting on whitespace. (ie. No, don't split that argument here either.) - Having to split some variable contents like
--foo --bar
according to shell quoting rules at a place of your choosing. (Triggering splitting at a place of your choosing is non-obvious because the approach you see recommended basically involves reconfiguring the parser using things likeset -f
(disable globbing) and modifying theIFS
(Input Field Separator), then triggering a reparse, and then setting them back... and you'd better hope you know all of the things likeset -f
that need to be set to known values.)
Having access to both --foo bar
and --foo=bar
allows you to use whichever form is most amenable to hacks such as "Valid contents for --foo
never contain spaces" to work around Bourne-family shells not having standardized arrays between them, the shells which do have them (eg. bash, zsh) making them feel very bolted-on, and environment variables having no array type.
from argh.
Thanks so much for doing that @RazrFalcon! Do you mind if I link to your table from the README?
Argument parsing is a multi-dimensional space and I hope people chose the tool that's right for them. We for example chose intentionally to not support the = syntax.
from argh.
@cavedweller am a fan of that choice, not supporting =
... more clean.
from argh.
@cavedweller Sure.
@tshepang Looks like a good candidate for a build feature.
from argh.
@ssokolow what are those quoting-related footguns that --for bar
(versus --foo=bar
) has?
from argh.
Some context,this tool wasn't written for linux, it was written for Fuchsia which has a very different set of constraints. This is called out in the first line of the README.
As of 2022 the README doesn't mention this. Does this mean that argh now properly support Linux/Unix conventions?
from argh.
Related Issues (20)
- add an attribute on option argument to let `from_str_fn` can return `Vec<T>` or `Option<T>` as-is HOT 7
- how skip a field like #[serde(skip)] HOT 2
- Is it possible to get a `TopLevelCommand`'s `FieldAttrs` with the current exposed API?
- positional arguments made on field with reserved named (ref_) keep the trailing _ in help text
- Negative switches
- Subcommand with no additional arguments? HOT 1
- Impossible to include angle brackets in help text in a way that satisfies argh and rustdoc
- Change `FromArgs::from_args` to accept `AsRef<str>`
- Support something like --helpfull which displays help for all subcommands HOT 2
- `#[argh(description = "...")]` only supports literal HOT 3
- Single dash is parsed as unrecognized argument HOT 1
- Disable automatically generated help message
- mutual exclusive options/switches
- don't work as a cargo-subcommand
- Any ability to specify 'raw' greedy args or pass-through?
- Consider making serde dependency optional (as a feature) HOT 1
- Inconsistent help-related behavior around subcommands
- Document `arg_name` attribute
- Unhelpfully-aimed error-messages on subcommands
- Positional arguments fail with negative numbers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from argh.