ini
ini copied to clipboard
REQUEST: add option to preserve 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
+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.
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.
If this is still something folks need feel free to submit a PR implementing the feature.