Giter Club home page Giter Club logo

Comments (5)

erickt avatar erickt commented on June 24, 2024 1

Yeah this would be interesting. We don’t have a built in way to do this at the moment, but you could use a helper function to do it. See this test for an example: https://github.com/google/argh/blob/master/argh/tests/lib.rs#L67. You’d just have to manually parse the argument into your enum.

from argh.

athre0z avatar athre0z commented on June 24, 2024

My preference for this would be another proc macro to annotate enums with, similar to how sub-commands are defined, except that these enums would not be allowed to have any data associated. Clap has this feature and calls it ValueEnum:

https://docs.rs/clap/latest/clap/trait.ValueEnum.html

from argh.

grantshandy avatar grantshandy commented on June 24, 2024

@bbstilson this is definitely possible with current argh. The intended way you're supposed to do this is by defining an enum with your "choices" then implementing FromStr on it. If your String input is only supposed to represent a finite number of values you should re-think storing it as a String, that's what enum was created for.

Good Luck!

from argh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.