Comments (7)
If you wanted to specifically take a delimited format, you could do that with a new-type pattern around a Vec<T>
, and then implement FromArgValue
or FromStr
for the new-type struct.
struct ServiceList(Vec<i32);
impl FromArgValue for ServiceList {
fn from_arg_value(value: &str) -> Result<Self, String> {
// parse to a Vec here
// or
impl FromStr for ServiceList {
type Error = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
// parse to a Vec here
from argh.
I have a similar request, which would be a way to allow options with multiple values, like --service s1 s2 s3
, perhaps with a delimiter
option so that --service s1,s2,s3
can also work.
from argh.
For repeated args, argh
supports a syntax like --service s1 --service s2 --service s3
.
The Vec<i32>
is created by calling the from_str_fn()
for each each value, which is why it expects a Result<i32,_>
.
from argh.
If you wanted to specifically take a delimited format, you could do that with a new-type pattern around a
Vec<T>
, and then implement [FromArgValue
]
That works great for me, cheers!
from argh.
I already mentioned in the issue description that newtype can solve the problem itself, and even gave a code example. But I think most use cases don't actually need a newtype, and adding one would just create redundant code. So I still prefer to add an option.
from argh.
That you did, sorry about missing that (this is what I get when I answer from the e-mail notification and only see the latest message added).
One way of doing this is that this is probably doable with a generic type, which could be added to the argh
crate:
(with const generics, which I don't remember the state of)
struct DelimitedList<T, D='c'> {
list: Vec<T>,
}
impl<T,D> FromStr for DelimetedList<T,D>
}
impl Deref for DelimitedList<> {
type TARGET: Vec<T>
...
}
@erickt - What do you think? comma-separated would be more tractable than space-separated (since the parser would see it as a single string, vs. needing to keep passing the next value to the same parser/accumulator). Or do we just tell people to use new-type and do it themselves, since the CLI rubric that we made argh
for is somewhat vague on repeated options (and I've heard other maintainers in the past say that it absolutely should require repeating the --arg-name
to repeat a value).
from argh.
Sure, I like this idea. My main consideration nowadays with things like this to make sure projects can maintain a rubric through code review. I’d be happy to take a patch that adds support for “-some_option=value” as long as it’s easy for a project like Fuchsia to say they don’t want their CLIs support it.
for this feature, it seems easy enough to add a “delimiter” feature so users don’t need to undo the new type trick. Maybe we treat a delimiter of ’ '
specially to be repeatable to allow for “—foo a b c —bar d”? might be worthwhile seeing how other libraries express support for this.
from argh.
Related Issues (20)
- Unrecognized argument on raw identifier
- Allow subcommand flattening HOT 3
- Process line breaks in description HOT 5
- [Optimisation] Stop re-parsing of commands for default sub commands
- Feature Request: choices HOT 5
- 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 2
- 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?
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.