Skip to content

Conversation

@sthuber90
Copy link

For instance handling systemd-networkd .network files is now working for duplicate keys. An example is provided below.

For a eth0.network file:

[Match]
Name=eth0

[Network]
Address=172.16.1.99/24
Gateway=172.16.1.1
DNS=172.16.1.1
DNS=8.8.8.8

The file is now parsed to:

{
  "Match": {
    "Name": "eth0"
  },
  "Network": {
    "Address": "172.16.1.99/24",
    "Gateway": "172.16.1.1",
    "DNS": [
      "172.16.1.1",
      "8.8.8.8"
    ]
  }
}

And encoded to the following string when using the new option isArray (Ideas for better naming are welcome):
ini.stringify(parsed, { isArray: false})
"[Match]\nName=eth0\n\n[Network]\nAddress=172.16.1.99/24\nGateway=172.16.1.1\nDNS=172.16.1.1\nDNS=8.8.8.8\n"

otherwise if you prefer to have [] present as a suffix after the key in a .ini file and it does not corrupt what the file is used for you can do as follows:
ini.stringify(parsed, { isArray: true})
or
ini.stringify(parsed)
will return:
"[Match]\nName=eth0\n\n[Match.Network]\nAddress=172.16.1.99/24\nGateway=172.16.1.1\nDNS[]=172.16.1.1\nDNS[]=8.8.8.8\n"

@sthuber90 sthuber90 closed this Mar 20, 2018
@sthuber90 sthuber90 reopened this May 1, 2021
@wraithgar
Copy link
Member

#204 solves this problem w/ a flag

@wraithgar wraithgar closed this Apr 12, 2023
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

Successfully merging this pull request may close these issues.

2 participants