Git Product home page Git Product logo

Comments (2)

kbknapp avatar kbknapp commented on May 30, 2024 2

Initial implementation may simply be a convenience macro, something like

let num = value_t!(matches.value_of("length"), u32);

This would allow far more types initially simply using Rust's &str.parse(), without crossing any lines (i.e where does clap validation stop, and developer validation start? What about parsing IP address, MAC addresses, etc....where is the line?). The more validation clap does, the bigger a performance hit everyone takes whether they want the validation or not.

What's unclear is if failure to parse should constitute ending the process? I'm leaning towards returning an Option<T> or Result<T,&str> which gives clap consumers the option to use .unwrap_or() for a default, or also deciding what to do upon a failed parse. I'm going to continue thinking about this before implementing...

The other nice thing about a macro initially is I could potentially include something like a decode_t! to decode a &str into a user defined enum. Now this would open the door for changing .possible_values() but I'm unsure about how to best implement this part without just requiring the consumer to manually type out each possibility of the enum into a possible values vec as is currently done.

from clap.

kbknapp avatar kbknapp commented on May 30, 2024 2

While this isn't the best solution, it does work for the time being. I'm still unsure how to best implement this in a way that is least taxing on the developer (i.e. I don't want to force people to implement custom traits, or anything like that...)

So this will remain TBD, but for now value_t! and value_t_or_exit! will at least get the job done in a somewhat efficient manner.

from clap.

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.