Comments (4)
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.
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.
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.
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)
- Getting a deprecated warning/error with clang 14 and CXXOPTS_USE_UNICODE_HELP ON HOT 1
- Comma Delimiter Breaking Quoted Strings HOT 2
- Inconsistent defaults when none specified [Bug?] HOT 1
- Support the use of std::optional's in cxxopts::ParseResult::as() HOT 3
- use woes under opensuse // Kdevelop HOT 1
- Integrate with google/oss-fuzz HOT 6
- Branch Name: main HOT 1
- About a new tag-release HOT 1
- feature request/question: support the one dash as argument HOT 2
- Feature request: value pairs or tuples HOT 1
- Renaming of OptionException should be mentioned in changelog HOT 1
- Allow "G", "M" and 'k' when parsing arguments HOT 2
- Getting a sign-conversion warning/error with clang 14 and CXXOPTS_USE_UNICODE_HELP ON HOT 2
- A proposition to implement any complex rule on the arguments
- unannotated fall-through between switch labels HOT 3
- Are unrecognized options supported? HOT 1
- std::bad_alloc during dlopen on integer_pattern initialization HOT 4
- In Linux systems, the tilde symbol (~) cannot be automatically expanded to "/home/user1," HOT 4
- -option Error message. I think we should not just report command ‘p’ error. HOT 5
- Report a typo in README.md doc(in master branch) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cxxopts.