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

stoml trimming \n from multi-line string #7

Open
ggmartins opened this issue May 10, 2021 · 2 comments
Open

stoml trimming \n from multi-line string #7

ggmartins opened this issue May 10, 2021 · 2 comments

Comments

@ggmartins
Copy link

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

@greg-szabo
Copy link
Contributor

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.

@greg-szabo
Copy link
Contributor

greg-szabo commented May 28, 2021

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.

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

2 participants