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

cannot create INI / TOML file with sections #4334

Closed
2 tasks
lukashartl opened this issue Apr 18, 2022 · 5 comments
Closed
2 tasks

cannot create INI / TOML file with sections #4334

lukashartl opened this issue Apr 18, 2022 · 5 comments
Labels

Comments

@lukashartl
Copy link
Contributor

Steps to Reproduce the Problem

I tried to do the example from VISION.md.

elektra@ebbe320775cc:~$ sudo kdb import system:/sw/samba/#0/current ini << HERE
[global]
workgroup=MYGROUP
HERE
elektra@ebbe320775cc:~$ cat /etc/samba/smb.conf
global = ""

Seems like there was a correct INI-Plugin once, but INI now falls back to using the NI-Plugin.

So I checked the TOML Plugin:

elektra@ebbe320775cc:~$ sudo kdb mount /etc/samba/smb.conf system:/sw/samba/#0/current toml
elektra@ebbe320775cc:~$ sudo kdb set system:/sw/samba/#0/current/global/workgroup MYGROUP
Create a new key system:/sw/samba/#0/current/global/workgroup with string "MYGROUP"
elektra@ebbe320775cc:~$ cat /etc/samba/smb.conf
global.workgroup = "MYGROUP"

Which also doesn't provide sections.

Expected Result

Sections :)

Actual Result

No sections :-(

System Information

  • Elektra: master
  • Operating System: Debian 11

Questions

  • Is it possible to create sections with the TOML-Plugin?
  • Why can't the INI (now NI) Plugin create sections?
@kodebach
Copy link
Member

Why can't the INI (now NI) Plugin create sections?

ini doesn't exist anymore, because it was kind of buggy. The fallback to ni is wrong IMHO, falling back to toml may work better.

The ni plugin uses a very specific format that on the surface looks like INI (as much as something can look like a format without a real specification). However, ni is not a general purpose INI format. It is designed specifically for specifications.

foo/bar = 123

[foo/bar]
meta:/type = short

[other/key]
meta:/type = string

The example above is in ni format. The first line defines the value of the key foo/bar as 123. The [foo/bar] section contains the metadata for the key foo/bar. Finally other/key has meta:/type set to string. Note: The meta:/ prefix is optional and the default value for a key is "".
So in your example ni read a key global with no value (defaults to "") and with metadata meta:/workgroup set to MYGROUP.

Is it possible to create sections with the TOML-Plugin?

Yes, toml should support section. Reading your example with toml should work fine:

sudo kdb import "system:/sw/samba/#0/current" toml << HERE
[global]
workgroup=MYGROUP
HERE

AFAIK toml tries to preserve the sections. However, if you create a new key with kdb set it may also use the dotted notation you've encountered. Of the top of my head I can't tell you want the exact rules are for when either notation is used. IIRC it is determined by the meta:/tomltype metakey. The toml README should have more information.

In general, if you want a specific file structure in human-readable formats, you should write the config file manually and the use kdb import to see what KDB structure you get. Like toml some plugins use metadata to remember the file structure, so creating a specific structure with kdb set can be tedious.

@lukashartl
Copy link
Contributor Author

Thank you, @kodebach ,

your example works fine if I add quotes:

elektra@d8942644af5b:~$ sudo kdb import "system:/test123" toml << HERE
[global]
workgroup = "MYGROUP"
HERE

So I would not be able to import the default config of samba, but at least I would be able to write something samba should be able to read.
I think toml would be a better default for ini than ni :)

I can also see, what I was missing:

elektra@9b5f78d99e76:~$ sudo kdb mount /etc/samba/smb.conf system:/sw/samba/#0/current toml
elektra@9b5f78d99e76:~$ sudo kdb meta-set 'system:/sw/samba/#0/current/global' 'tomltype' 'simpletable'
elektra@9b5f78d99e76:~$ sudo kdb set system:/sw/samba/#0/current/global/workgroup MYGROUP
Create a new key system:/sw/samba/#0/current/global/workgroup with string "MYGROUP"
elektra@9b5f78d99e76:~$ cat /etc/samba/smb.conf 
[global]
workgroup = "MYGROUP"

So I have to add tomltype to every keyset of every section of the samba config (e.g. every share), but that's ok now that I know it :)

We should definitely add the word section somewhere in the README of the toml plugin ;) First and foremost to add it to the search and secondly, I mostly skim through docs by (CTRL+F) and keywords and I couldn't find it ... my bad 😏

@kodebach
Copy link
Member

your example works fine if I add quotes:

Yes, that's true TOML needs quotes around strings. In theory the plugin could be adapted to allow unquoted strings. But that 100% spec-conforming TOML, so it would need a config option.

We should definitely add the word section somewhere in the README of the toml plugin ;)

That's a good point. TOML uses the term "table" for sections, so we should probably note that somewhere for people coming from INI.

@github-actions
Copy link

I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue.
Thank you for your contributions 💖

@github-actions github-actions bot added the stale label Apr 19, 2023
@github-actions
Copy link

github-actions bot commented May 4, 2023

I closed this now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue.
Thank you for your contributions 💖

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants