Skip to content
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

Implement choice enums #196

Merged
merged 4 commits into from
Feb 4, 2025
Merged

Implement choice enums #196

merged 4 commits into from
Feb 4, 2025

Conversation

kovaxis
Copy link
Contributor

@kovaxis kovaxis commented Feb 4, 2025

This PR implements #138.

Basically, it allows using simple fieldless enums as arguments by deriving FromArgValue:

#[derive(FromArgValue)]
enum MyChoiceEnum {
    Black,
    Yellow,
}

#[derive(FromArgs)]
struct Args {
    #[argh(option)]
    color: MyChoiceEnum,
}

Additionally:

  • I convert the PascalCase names of enum variants into snake_case, so that the code above could be run as ./some_bin --color black or ./some_bin --color yellow.

  • #[argh(name = "arbitrary_name") attributes are allowed to specify any desired name for each variant.

  • I implemented better error messages like Error parsing option '--color' with value 'purple': expected "black" or "yellow"

  • I did not implement listing available options in the help message, because that would require some heavier refactoring and I am not very familiar with the codebase yet.

  • I added some basic documentation to the lib.rs top-level doc-comment, to the simple example and to the FromArgValue trait, as well as tests.

Copy link

google-cla bot commented Feb 4, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@sadmac7000
Copy link
Collaborator

Looks like one of our workflow tests in broken. You can fix it by changing .github/workflows/rust.yml

@kovaxis
Copy link
Contributor Author

kovaxis commented Feb 4, 2025

Should be done. Is there anything left to do? I noticed there is no changelog.

@sadmac7000 sadmac7000 merged commit 79d3022 into google:master Feb 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants