Optionally write comments to config files#180
Open
srivathsanmurali wants to merge 1 commit intohyperrealm:masterfrom
Open
Optionally write comments to config files#180srivathsanmurali wants to merge 1 commit intohyperrealm:masterfrom
srivathsanmurali wants to merge 1 commit intohyperrealm:masterfrom
Conversation
hyperrealm
reviewed
Oct 1, 2021
| setting->config = parent->config; | ||
| setting->hook = NULL; | ||
| setting->line = 0; | ||
| setting->comment = (comment == NULL) ? NULL : strdup(comment); |
Owner
There was a problem hiding this comment.
__config_setting_destroy() needs to be updated to free this string, otherwise we have a memory leak
| // --------------------------------------------------------------------------- | ||
|
|
||
| Setting & Setting::add(const char *name, Setting::Type type) | ||
| Setting & Setting::add(const char *name, Setting::Type type, const char *comment) |
Owner
There was a problem hiding this comment.
should have an overload that takes a const std::string &comment (a simple inline function in libconfig.h++)
doc/libconfig.texi needs to be updated with documentation for the new APIs.
Owner
There was a problem hiding this comment.
also a couple of unit tests would be nice
|
|
||
| extern LIBCONFIG_API config_setting_t *config_setting_add( | ||
| config_setting_t *parent, const char *name, int type); | ||
| extern LIBCONFIG_API config_setting_t *config_setting_add_with_comment( |
Owner
There was a problem hiding this comment.
We should have a config_setting_set_comment() function as well.
| { | ||
| if(depth > 1) | ||
| __config_indent(stream, depth, config->tab_width); | ||
| fprintf(stream, "// %s\n", setting->comment); |
Owner
There was a problem hiding this comment.
If the comment contains newlines, this will result in a syntax error in the generated file. The comment should be written out such that each line begins with //.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the functionality to optionally add comments while writing configs. This helps give the user an idea about what the setting is.
You can add comments to your settings by using the following API as demonstrated in the example3
For C: We have a new function to add settings
For C++, we make use of polymorphism in C++
example3 produces the following output