Skip to content
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

REQUEST: add option to preserve comments #32

Closed
phun-ky opened this issue Oct 6, 2014 · 3 comments
Closed

REQUEST: add option to preserve comments #32

phun-ky opened this issue Oct 6, 2014 · 3 comments

Comments

@phun-ky
Copy link

phun-ky commented Oct 6, 2014

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

@gavinengel
Copy link

+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.

@exse2
Copy link

exse2 commented Sep 2, 2021

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.

@wraithgar
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants