hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.1k stars 360 forks source link

Optionally write comments to config files #180

Open srivathsanmurali opened 3 years ago

srivathsanmurali commented 3 years ago

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

  group = config_setting_add_with_comment(
      root, "address", CONFIG_TYPE_GROUP, "Address for parcel delivery");

For C++, we make use of polymorphism in C++

  Setting &address = root.add("address", Setting::TypeGroup, "Address for parcel delivery");

example3 produces the following output

// Address for parcel delivery
address :
{
  street = "1 Woz Way";
  city = "San Jose";
  state = "CA";
  zip = 95110;
};
numbers = [ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 ];