-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow specifying types for arguments #818
Comments
I agree that custom shell completion is needed, which is the discussion for #568 but I think these three issues (type conversion for args, stringly typed arg keys, and custom shell completions) are separate issues that I wouldn't want to mix. I'll expand a little bit. Type ConversionsThis can already be done via macros ( IMO, but I'm up for discussion, fn value_of(&self, arg: &str) -> T {
// ...
} Unless I'm misunderstanding what you're asking for. What I'd like to do is provide a way someone to either specify upfront what the type is (thing something like a functional The point being all the work is done for you, minus maybe specifying the type, which isn't any worse than what you're already doing by specifying the parameters for the arg. This should look something like #[derive(FromMatches)]
struct Args {
num: u64
}
// ---
let args: Args = matches.into();
if args.num > 28 { /* do stuff */ }
// Instead of
if matches.value_of("num").unwrap() > 27 { /* do stuff */ } Stringly Typed Arg KeysThis can be done today by using enums and impl'ing It will look like: #[derive(ArgKey)]
enum Foo {
Bar,
Baz,
Qux
}
// ---
let value = matches.value_of(Foo::Baz); Which has a huge benefit of compile time checking of keys and one of biggest pain points of Custom Shell CompletionAs discussed in #568 this is something I really want. But unlike the two above, there really isn't a way to do this today. When I originally wrote the shell completions portions of The problem with implementing this is I just haven't had a good time to sit down and think about how (because of work, holidays, family, etc.). I want a way to specify this that abstracts well enough to work for all shells. The easiest way is to say, "Put your arbitrary completion shell script here inside this Sorry for the long discussion, but please let me know if I'm off on any bases. |
I'm going to close this issue since it's covered by individual other issues. Please let me know if it needs to be re-opened for something outside the issues listed above. |
Feature discussion/request: add something like Python's click library's "types".
There are two big reasons to do this:
It seems like a:
Might be a good-enough start.
1: Maybe this should be a separate bug, but: it's mildly annoying that ripgrep's auto-completion behavior (in zsh) is as follows:
And in particular that once I've got part of the path that I want to search it refuses to complete it, so I have this behavior:
The text was updated successfully, but these errors were encountered: