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

std.manifestIni should support repeated section names #1125

Open
robinp opened this issue Jan 21, 2024 · 0 comments
Open

std.manifestIni should support repeated section names #1125

robinp opened this issue Jan 21, 2024 · 0 comments

Comments

@robinp
Copy link

robinp commented Jan 21, 2024

Hello. This is a change request similar in spirit to #386 (fixed in d4434c8), but this time to allow sections with duplicate names (instead of duplicate keys).

The INI file wiki acknowledges this exists. As a specific example, wireguard needs multiple [Peer] sections.

Modifying the upstream std like this, by adding the array-check in section_lines, seems to work (now if a value of a key within sections is an array, then that section will be repeated):

  manifestIni(ini):
    local body_lines(body) =
      std.join([], [
        local value_or_values = body[k];
        if std.isArray(value_or_values) then
          ['%s = %s' % [k, value] for value in value_or_values]
        else
          ['%s = %s' % [k, value_or_values]]

        for k in std.objectFields(body)
      ]);

    local section_lines(sname, value_or_values) = 
            if std.isArray(value_or_values) then
              local rep = value_or_values;
              std.join([], [
                ['[%s]' % [sname]] + body_lines(sbody)
                for sbody in rep
              ])
            else
              local sbody = value_or_values;
              ['[%s]' % [sname]] + body_lines(sbody),
          main_body = if std.objectHas(ini, 'main') then body_lines(ini.main) else [],
          all_sections = [
      section_lines(k, ini.sections[k])
      for k in std.objectFields(ini.sections)
    ];
    std.join('\n', main_body + std.flattenArrays(all_sections) + ['']),
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

1 participant