Comments (4)
This is actually intended behavior and has been brought up before in #16. Here's an edit of my response:
Yea, my concern with having that style of optional argument is that it actually introduces a third state to the flag.
- flag not specified
- flag specified followed by non-flag
- flag specified followed by a flag (and thus specified without argument)
Currently a flag has two states:
- flag not specified
- flag specified with argument
I feel like if there's some default behavior you want with a flag specified with no argument it can be captured by its own flag. Consider
git log
for example,--oneline
is equivalent to--pretty=oneline
.Also, it messes with the current greedy argument behavior. For example,
foo --log --verbose
would make--verbose
an argument to--log
.
I'm open to further discussion on this though.
from argagg.
Hi,
I read that issue, and agree with your assessment; however, the --def-opt flag still does not work as stated on the main page readme:
If you want to get an option argument but fallback on a default value if it doesn't exist then you can use the argagg::option_results::as() API and provide a default value
When the value doesn't exist, I actually get that error described in my opening post. Am I misunderstanding this?
Thanks
from argagg.
I see, the wording in my README is poor then. I think it is more precisely worded as:
If you want to get an option argument but fallback on a default value if the option is not specified then you can use the argagg::option_results::as() API and provide a default value.
For the sample, I added some unit test cases that hopefully clarify the behavior:
- c79fe8a#diff-66a301af68cc98d54d6f489be5a4699aR114
- c79fe8a#diff-66a301af68cc98d54d6f489be5a4699aR154
- c79fe8a#diff-66a301af68cc98d54d6f489be5a4699aR161
- https://travis-ci.org/vietjtnguyen/argagg/builds/373669320
Let me know if that clarifies the behavior or not.
from argagg.
Ah OK, I understand better now. Thanks for the clarification.
from argagg.
Related Issues (20)
- Correctly handle parse errors from strtol, strtoll, strtof, and strtod HOT 1
- Simplify base constructor inheritance HOT 2
- argagg::definition should have a move constructor
- Get rid of definition names, key by the option itself
- Cannot use the NOT operator in VS2017 HOT 5
- Optional argument param HOT 3
- Allow `-long_name` HOT 5
- argagg::parser_results::operator[] throws std::out_of_range when key does not exsits HOT 3
- Key errors when getting option results should have a custom exception HOT 1
- Support for options like -std=foo HOT 3
- Support for sinks of unparsed arguments HOT 1
- Doc Issue
- get rid of mandatory iostreams dependency
- Add a CMake interface target
- bool argument HOT 2
- CMake Deprecation Warning
- Warnings on MSVC: unused local variable HOT 1
- incorrect integer conversion
- Add global order of options 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 argagg.