STOML is a simple TOML file parser for the Linux Shell (bash, ksh, csh, etc). The purpose is to easily parse INI files. TOML is a generalized INI file, so a simplified TOML parser can get this done.
Tom's Obvious, Minimal Language is defined here.
Check the releases page.
Install Golang, then run:
GO111MODULE=on go get github.com/freshautomations/stoml.git
To get a key
from a file called filename
and export it as a Bash environment variable, run
export MYVALUE=`stoml filename key`
TOML can also have sections. They are referred to with dotted paths:
export MYSECTIONVALUE=`stoml filename mysection.key`
This is a simple
implementation of parsing TOML.
This means that it will work well with atomic types in the configuration, like string, int or boolean.
It also means that more complex types like floats, lists or maps will be translated by Go as it sees fit.
Examples for output:
myint = +4
#Export as "4"
myfakeint = "+4"
#Export as "+4"
mystring = "hello hi g'day howdy"
#Export as "hello hi g'day howdy"
mylist = [1,2,3]
#Export as "1 2 3"
Note: floats that have 9 zeros after the dot (epsilon = 10^-9) are presented as integers. Viper's toml converter somehow converts big integers to float and presents them in the exponential format. This way we work around that.
The application will try to figure out what kind of file was it fed.
*.toml
files will be parsed as TOML but as a side-effect of the viper library,
the application can also parse JSON files (*.json
) and YAML (*.yml
) files.
By default, any other file types (for example INI) are treated as TOML files.
This side-effect is used during the release of the application to parse incoming JSON responses from the GitHub API. It's not a main feature though.