google / google/argh

Feature Request: choices

Open
#138 5 comments 3 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
102
PR merge metrics
No merged PRs in 30d

Description

Similar to the [click](https://click.palletsprojects.com/en/8.1.x/options/#choice-options) arg parse library from Python, it would be nice if `argh` had a similar feature. I am new to rust, so I can't suggest a good interface, but perhaps something like:

```rust
#[derive(FromArgs, Debug)]
struct Args {
#[argh(choice, choices = vec!["foo", "bar", "baz"])]
thing_type: String
}
```

but an enum might be a better option:

```rust
#[derive(Debug)]
enum Choice {
Foo, Bar, Baz
}

#[derive(FromArgs, Debug)]
struct Args {
#[argh(choice, choices = Choice)]
thing_type: Choice
}
```

Perhaps this is possible already, but I couldn't figure out how to do so given the example and readme. Happy to close this if it is already possible.

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.