GithubHelp home page GithubHelp logo

Required arguments about cxxopts HOT 4 CLOSED

jarro2783 avatar jarro2783 commented on June 9, 2024
Required arguments

from cxxopts.

Comments (4)

jarro2783 avatar jarro2783 commented on June 9, 2024

I'm reluctant to do this, and something similar was raised in #25. The reason being that I don't think the parser should have any logic in it. The problem is that in general, you can't just say that an argument is required or not. There are some specific cases where it works, but a lot of the time, arguments are required based on the presence of other arguments. I would rather leave that logic up to the program.

from cxxopts.

crusader-mike avatar crusader-mike commented on June 9, 2024

I agree with OP -- simple method will certainly simplify my life (as in I don't need to write it myself). Something very trivial, like:

class Options {
...
template<class T>
T const& required(string const& opt)
{
    if (!count(opt))
        throw ...(u8"Option ‘%s’ is required", opt.c_str());
    return (*this)[opt].as<T>();
}
...
};

Also, you may want to clean up this code a bit -- I skimmed over it and noticed few strange pieces (like calling std::move on string const&). Don't take it personally -- it is a neat little library and it seem to get it's task done.

from cxxopts.

jarro2783 avatar jarro2783 commented on June 9, 2024

I'll see if I can add something simple for required options. It seems to be the most requested feature, and something simple should be ok. As long as it is understood that anything more complicated belongs in the main program.

Thanks for pointing out the strange things in it. It has been around for a while and acquired some cruft.

from cxxopts.

patrikhuber avatar patrikhuber commented on June 9, 2024

Hi,

I have been searching for this for quite a while. I don't think this is documented anywhere. Shall we add this to the wiki? It's meant to be used as follows, correct?

cxxopts::check_required(options, { "option1", "option2" });

from cxxopts.

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.