-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config_to_str() ignores options with empty strings #537
Comments
I will look into it a little more today |
I did some investigations, using the JSON custom config implementation. This one behaves similar regarding empty strings. I got the impression the problem comes from using strings as internal representation for values, and string::empty() as indicator for non existing values. This takes away the chance to treat empty string values as normal values. I think values should be stored as some "optional" type, not overriding the meaning of an empty string. But this would require a major redesign I guess. Or do you see a simple solution/workaround? BTW; I didn't find any information about the native value type in an option instance. I think this is the reason why JSON config example generates only string output for config files, not native values like true/false for booleans, etc? |
@phlptp, did you find some chance to look into it? |
I have not yet, but it is next on my list after finishing #545 |
Well correction I did look into it earlier but haven't resolved anything regarding it yet. So I will take another crack at it soon |
Been messing around with this This is where I am at currently in that I have a way in that branch to do everything specified in this Issue. I need to clean up a few things and add documentation before it is ready for a PR though, so probably a couple days before I get to polishing it up. The main config follows toml specification and a distinction between strings and single characters which is where that default comes from, so I don't really want to change that. What I added was an ability to modify the config formatter to specify the exact quote characters to use in those contexts which means you can set them both to use single quote or double quote or some combination of them. Regarding the default, if the default string given is empty that is the equivalent to clearing any default value, and there needs to be a way to do that so can't really be modified without adding a few functions and other structures. But the exception to that was if the option callback is forced, which would mean even if the argument wasn't given the callback for the option is used. In which case the default is used whether or not it was given. The modification was to extend this to the config output as well, so it will print regardless of what the default is. I added the example and several tests about it to the cmake testing configuration. |
Hey, many thanks for doing such serious and deep investigation. I just read your comment, will check details later, quite busy right now. I'm curious if/how I can solve this with your extensions! |
the config app example in that branch is basically the example you supplied with the minor tweaks to make the output the one you desired. Namely setting the config_formatter quote characters and adding the always run callback to the file option. |
Hi again,sorry for the delay. I looked at your branch now and can confirm that all cases works now as expected. As you mentioned, there are some changes in the code base and in the example code required. Some notes from a naive user: requiring Overall I understand that making bigger changes is not so easy! The concept using empty strings for absent values is not optimal, maybe, but anyway, it works. Thanks! I let the issue open, you close it after merging I guess. |
Hi, I found another edge case: $ build/examples/config_app -p -f 1
file=1
count=0
flag=false
double=0
$ build/examples/config_app -p -f "1"
file=1
count=0
flag=false
double=0 In this case, the string is like a number, but should be a string. I guess this is more complicated... |
I just tried version 2.0.0, the empty string problem is solved with it! Many thanks, great work! |
Hi there,
I'm experimenting with CLI11 version 1.9.1. I used boost::program_options for some years now and I'm looking for something smarter, with less cryptic syntax and less boilerplate code. Typically I offer a
--print
option in my programs, to print the current configuration to the console, and a--config
option for reading such an config file in.This works so far, but I have one problem, and cannot find a simple way to solve this. I want all options in the configuration file, including default values and empty strings. But the latter are not printed. Furthermore, there is a different format used for single character strings. Here is the
simple
example with my extensions:Here is the output for different values:
I would like to have:
file=""
but it is missing completelyfile="/"
but I get single quotesfile="/tmp"
this is finefile=""
surprise! This looks like expected"/"
another surprise, same as number 2Is there a simple way to get the expexcted output? Or do I have to write a custom
Config
implementation for that?The text was updated successfully, but these errors were encountered: