ini icon indicating copy to clipboard operation
ini copied to clipboard

REQUEST: add option to preserve comments

Open phun-ky opened this issue 11 years ago • 2 comments

I'm using ini to parse a nexus deploy configuration file, and by all means, it works great, but our java developers has the habit of using comments in this configuration file, and ini.parse removes all text after strings with # and ;.

Example

Desired outcome:

# Supports interpolation
# Can reference other values in same section or in special default section
# To reference myValue, you need to write: %(myValue)s

[DEFAULT]
....
syslog.local0.levels=info;error

Actual outcome:

[DEFAULT]
....
syslog.local0.levels=info

I'm using [email protected], [email protected] and [email protected] in a windows 7 environment with git bash

phun-ky avatar Oct 06 '14 18:10 phun-ky

+1 I'd like this all well. Basically what I want is a way to make simple edits to ini/cnf files on the Linux CLI. I want to ensure that comments are retained. Perhaps using this method: http://fadefade.com/json-comments.html or perhaps into cson?

By the way, if you change the # in the ini file to a \# with backslash before it, it sortof retains the comments, but it still outputs them messy with a =true at the end. If you can remove the =true at the end this could be the start of a quick way to deal with this stuff.

gavinengel avatar Apr 26 '15 04:04 gavinengel

hello person from 2014. just use this and call it a day:

npm install --save --no-package-lock --unsafe-perm=true ini-api

  import fs from 'fs';
  import iniApi from 'ini-api';
  const Ini = iniApi.Ini;
  
  (async () => {
	  let text = fs.readFileSync('/etc/systemd/journald.conf', 'utf-8');
	  let ini = new Ini(text);
	  ini.getSection('Journal').setValue('Storage', 'persistent');
	  fs.writeFileSync('./config_modified.ini', ini.stringify())
  })();

it retains comments.

exse2 avatar Sep 02 '21 13:09 exse2

If this is still something folks need feel free to submit a PR implementing the feature.

wraithgar avatar Apr 13 '23 18:04 wraithgar