#toml #bash #format #serialization #db #nested #interopability

app tombl

Interopability between bash and the TOML serialization format

1 unstable release

0.2.2 Aug 26, 2022

#2292 in Encoding

Download history 4/week @ 2024-03-14 3/week @ 2024-03-21 10/week @ 2024-03-28 9/week @ 2024-04-04 64/week @ 2024-04-11

63 downloads per month

GPL-3.0-only

9KB
177 lines

tombl

tombl makes bash viable for DevOps-automations that involve configurations saved as .toml files.

It allows bash to read .toml files structurally, so you don't have to come up with weird ad-hoc solutions involving awk, sed, and tears as soon as it breaks in production because you didn't use an actual toml-parser.

$ set -euo pipefail
$ tombl -e DB=databases.hmm /etc/my-config.toml
declare -A DB=(["user"]="postgreker" ["password"]="super secret" ["host"]="0.0.0.0" ["port"]=5432)
$ eval "$(tombl -e DB=databases.hmm /etc/my-config.toml)"
$ echo "${DB[user]}"
postgreker
$ pg_dumpall -h "${DB[host]}" -p "${DB[port]}" -u "${DB[user]}" > out.sql

Bash is unable to store nested arrays of any kind, so any nesting will be ignored when exporting, and you'll have to adapt your -e VAR=path.to.thing to access the nested information. It is recommended that you start your scripts with set -euo pipefail in order to fail fast™.

$ set -euo pipefail
$ cat /etc/my-config.toml
[databases.hmm]
user = "postgreker"
password = "super secret"
host = "0.0.0.0"
port = 5432
thing-that-is-nested = { will-not-be-included = 123 }
$ tombl -e DB=databases.hmm /etc/my-config.toml
declare -A DB=(["user"]="postgreker" ["password"]="super secret" ["host"]="0.0.0.0" ["port"]=5432)
$ eval "$(tombl -e DB=databases.hmm /etc/my-config.toml)"
$ echo "${DB[thing-that-is-nested]}" # whoops, but this will fail fast because of `set -euo`
bash: l: unbound variable

Dependencies

~1.5–2.2MB
~43K SLoC