Comments (2)
Initial implementation may simply be a convenience macro, something like
let num = value_t!(matches.value_of("length"), u32);
This would allow far more types initially simply using Rust's &str.parse()
, without crossing any lines (i.e where does clap
validation stop, and developer validation start? What about parsing IP address, MAC addresses, etc....where is the line?). The more validation clap
does, the bigger a performance hit everyone takes whether they want the validation or not.
What's unclear is if failure to parse should constitute ending the process? I'm leaning towards returning an Option<T>
or Result<T,&str>
which gives clap
consumers the option to use .unwrap_or()
for a default, or also deciding what to do upon a failed parse. I'm going to continue thinking about this before implementing...
The other nice thing about a macro initially is I could potentially include something like a decode_t!
to decode a &str into a user defined enum
. Now this would open the door for changing .possible_values()
but I'm unsure about how to best implement this part without just requiring the consumer to manually type out each possibility of the enum
into a possible values vec as is currently done.
from clap.
While this isn't the best solution, it does work for the time being. I'm still unsure how to best implement this in a way that is least taxing on the developer (i.e. I don't want to force people to implement custom traits, or anything like that...)
So this will remain TBD, but for now value_t!
and value_t_or_exit!
will at least get the job done in a somewhat efficient manner.
from clap.
Related Issues (20)
- Can not compile clap success when I use toolchain nightly-x86_64-unknown-linux-gnu HOT 4
- `#[arg(value_delimiter = ':')]` Delimiter isnt displayed in the help message. HOT 1
- Deprecate and remove `clap_complete_fig`? HOT 2
- clap_dervie doesnt working on rust version 1.72.1 HOT 4
- build delta-inspect raise could not find `delta_datafusion` in the crate root HOT 2
- doesn't recognize numbers in hex or binary notation HOT 5
- Documentation issue: clap::_derive::_tutorial::chapter_* links to clap::_tutorial instead of clap::_derive::_tutorial HOT 1
- Cannot use non-literal expressions for `name` attribute HOT 1
- clap_complete documentation should clearly point to CommandFactory HOT 1
- [derive] Argument `test`'s selected action SetTrue contradicts `takes_value` HOT 5
- Write-up of opt-in deprecation warnings? HOT 4
- Delegate completions for a specific argument to the completions of an external program HOT 3
- Visually Separate ArgGroups HOT 2
- Support Base Path for ValueHint::*Path types HOT 1
- Clap-generated shell completion failing on macOS /bin/bash with: conditional binary operator expected: syntax error near `IFS' HOT 3
- `flatten` with `required` breaks requirement checking HOT 1
- `demo.rs` does not compile on its own HOT 4
- Multilingual Help Commands HOT 2
- Environment variable name aliases HOT 1
- Arg dynamic completion via `ValueHint::Execute(String)` HOT 1
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 clap.