freshautomations/stoml

stoml trimming \n from multi-line string

Opened this issue · 2 comments

thanks for the great work, here's a small thing to consider:

[cron]
test1 ="""
tetst ad EOL
te sdsa ads EOL
scs scd EOL
"""
~/go/bin/stoml myconf.toml cron.test1
tetst ad EOL te sdsa ads EOL scs scd EOL

expected:

python3 -c "import toml; print(toml.load('myconf.toml')['cron']['test1']) "
tetst ad EOL
te sdsa ads EOL
scs scd EOL

Hi @ggmartins ! Thanks for the submission.

Very interesting issue, I didn't think about it with my original use-case of VAR=$(stoml file entry), which would have made it a single line, no matter what. (Hence the S in the name: simple.)

I'll check if I can easily fix it.

As mentioned above the original use-case was for Linux shell scripts to easily/concisely manage configuration options. In most cases, a space-separated list is more useful, because it can be further processed in, for example, loops.

In your case, adhering to the TOML specification is more important. Although this was never really the purpose, it's still an edge case that's worth fixing. In the latest v0.6.2 release, I've introduced a -m parameter. If you add this parameter, the input entry will be read as-is as a string and printed out as-is. This will work for this multi-line case. (This is contrary to the default case of reading everything as a list of strings and then concatenating it with spaces.)

I hope this is a good workaround for your case. In the future, I'm planning to merge stoml with the sconfig tool, and with that I will most probably redesign the use-cases and adhere to the TOML standard better.