Elektra
0.9.4
|
This plugin is a storage plugin for reading and writing TOML files. The plugin retains most of the file structure of a read TOML file such as comments, empty lines and TOML tables. It supports all kinds of TOML specific types and tables, including nested inline tables and multiline strings.
The plugin needs Flex (>=2.6.2) and Bison (>=3) for parsing TOML files.
On reading, the plugin will set the type
metakey for strings, integers, floats and boolean values, if applicable. For decimal integers, the metakey is set to long_long
. For binary/octal/hexadecimal integers, the metakey is set to unsigned_long_long
. For floats, the metakey will be set to double
. These types are chosen to conform with the TOML format as stated on the offical TOML page.
On reading, non-decimal integers will get converted to decimal. The non-decimal representation will be stored in the origvalue
metakey of the key. When writing a key, the value of that metakey will be written instead, in order to retain the original format. Note that the origvalue
metakey gets removed if the value of the key changes.
``` sudo kdb mount test.toml user:/tests/storage/types toml type
echo 'plain_decimal = 1000' >> kdb file user:/tests/storage/types
echo 'file_permissions = 0o777' >> kdb file user:/tests/storage/types
echo 'pi = 3.1415' >> kdb file user:/tests/storage/types
echo 'division_gone_wrong = -inf' >> kdb file user:/tests/storage/types
cat kdb file user:/tests/storage/types
kdb meta-get 'user:/tests/storage/types/plain_decimal' 'type'
kdb get 'user:/tests/storage/types/plain_decimal'
kdb meta-get 'user:/tests/storage/types/file_permissions' 'type'
kdb get 'user:/tests/storage/types/file_permissions'
kdb meta-get 'user:/tests/storage/types/pi' 'type'
kdb get 'user:/tests/storage/types/pi'
kdb meta-get 'user:/tests/storage/types/division_gone_wrong' 'type'
kdb get 'user:/tests/storage/types/division_gone_wrong'
kdb rm -r user:/tests/storage/types sudo kdb umount user:/tests/storage/types
sudo kdb mount test.toml user:/tests/storage/types toml type
kdb set 'user:/tests/storage/types/value' '1'
kdb meta-get 'user:/tests/storage/types/value' 'type'
cat kdb file user:/tests/storage/types
kdb meta-set 'user:/tests/storage/types/value' 'type' 'boolean'
cat kdb file user:/tests/storage/types
kdb meta-set 'user:/tests/storage/types/value' 'type' 'string'
cat kdb file user:/tests/storage/types
kdb rm -r user:/tests/storage/types sudo kdb umount user:/tests/storage/types
sudo kdb mount test.toml user:/tests/storage/numbers toml type
kdb set 'user:/tests/storage/numbers/a' '0o777'
kdb get 'user:/tests/storage/numbers/a'
kdb meta-get 'user:/tests/storage/numbers/a' 'origvalue'
kdb meta-get 'user:/tests/storage/numbers/a' 'type'
kdb meta-set 'user:/tests/storage/numbers/a' 'origvalue' '0o666'
kdb get 'user:/tests/storage/numbers/a'
kdb meta-set 'user:/tests/storage/numbers/a' 'origvalue' '0o888'
kdb meta-get 'user:/tests/storage/numbers/a' 'type'
kdb rm -r user:/tests/storage/numbers sudo kdb umount user:/tests/storage/numbers
sudo kdb mount test_strings.toml user:/tests/storage toml type
kdb set 'user:/tests/storage/string' 'I am a basic string a literal one.'
kdb get 'user:/tests/storage/string'
kdb set 'user:/tests/storage/string' 'I am a basic string\not a literal one.'
kdb get 'user:/tests/storage/string'
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage
sudo kdb mount test_binary.toml user:/tests/storage toml type
kdb set 'user:/tests/storage/nullkey'
cat kdb file user:/tests/storage
echo "base64 = '@BASE64SSBhbSBiYXNlIDY0IGVuY29kZWQgZm9yIG5vIHJlYXNvbi4='" > kdb file user:/test
kdb get 'user:/test/base64' #>
echo -e kdb get 'user:/test/base64'
#> I am base 64 encoded for no reason.
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage
sudo kdb mount test_table.toml user:/tests/storage toml type
kdb set 'user:/tests/storage/common/a' '0' kdb set 'user:/tests/storage/common/b' '1' kdb set 'user:/tests/storage/common/c' '2'
cat kdb file user:/tests/storage
#> common.a = 0 #> common.b = 1 #> common.c = 2
kdb meta-set 'user:/tests/storage/common' 'tomltype' 'simpletable'
cat kdb file user:/tests/storage
#> [common] #> a = 0 #> b = 1 #> c = 2
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage
sudo kdb mount test_table_array.toml user:/tests/storage toml type
kdb meta-set 'user:/tests/storage/tablearray' 'tomltype' 'tablearray' kdb set 'user:/tests/storage/tablearray/#0/a' '1' kdb set 'user:/tests/storage/tablearray/#0/b' '2'
kdb set 'user:/tests/storage/tablearray/#1/a' '3' kdb set 'user:/tests/storage/tablearray/#1/b' '4'
kdb meta-get 'user:/tests/storage/tablearray' 'array' #> #1
cat kdb file user:/tests/storage
#> [[tablearray]] #> a = 1 #> b = 2 #> [[tablearray]] #> a = 3 #> b = 4
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage
sudo kdb mount test_inline_table.toml user:/tests/storage toml type
kdb meta-set 'user:/tests/storage/inlinetable' 'tomltype' 'inlinetable' kdb set 'user:/tests/storage/inlinetable/a' '1' kdb set 'user:/tests/storage/inlinetable/b' '2' kdb meta-set 'user:/tests/storage/inlinetable/nested' 'tomltype' 'inlinetable' kdb set 'user:/tests/storage/inlinetable/nested/x' '3' kdb set 'user:/tests/storage/inlinetable/nested/y' '4'
cat kdb file user:/tests/storage
#> inlinetable = { a = 1, b = 2, nested = { x = 3, y = 4 } }
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage
sudo kdb mount test_array.toml user:/tests/storage toml type
kdb set 'user:/tests/storage/array/#0' '1' kdb set 'user:/tests/storage/array/#1' '2' kdb set 'user:/tests/storage/array/#2' '3'
kdb meta-get 'user:/tests/storage/array' 'array' #> #2
cat kdb file user:/tests/storage
#> array = [1, 2, 3]
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage
sudo kdb mount test_comments.toml user:/tests/storage toml type
kdb set 'user:/tests/storage/key' '1'
kdb meta-set 'user:/tests/storage/key' 'comment/#0' ' This value is very interesting' kdb meta-set 'user:/tests/storage/key' 'comment/#0/space' '4'
kdb meta-set 'user:/tests/storage/key' 'comment/#1' ' I am the top-most comment relative to my key.' kdb meta-set 'user:/tests/storage/key' 'comment/#2' ' I am in the middle. Just boring.' kdb meta-set 'user:/tests/storage/key' 'comment/#3' ' I am in the line right above my key.'
kdb meta-set 'user:/tests/storage' 'comment/#1' ' First file-ending comment' kdb meta-set 'user:/tests/storage' 'comment/#2/start' '' kdb meta-set 'user:/tests/storage' 'comment/#3' ' Second file-ending comment. I am the last line of the file.'
cat kdb file user:/tests/storage
#> # I am the top-most comment relative to my key. #> # I am in the middle. Just boring. #> # I am in the line right above my key. #> key = 1 # This value is very interesting #> # First file-ending comment #> #> # Second file-ending comment. I am the last line of the file.
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage
sudo kdb mount test_array_comments.toml user:/tests/storage toml type
kdb set 'user:/tests/storage/array/#0' '1' kdb set 'user:/tests/storage/array/#1' '2' kdb set 'user:/tests/storage/array/#2' '3'
kdb meta-set 'user:/tests/storage/array' 'comment/#0' ' Inline comment after the array' kdb meta-set 'user:/tests/storage/array' 'comment/#0/start' '#' kdb meta-set 'user:/tests/storage/array' 'comment/#0/space' '5'
kdb meta-set 'user:/tests/storage/array/#0' 'comment/#0' ' Inline comment of first element' kdb meta-set 'user:/tests/storage/array/#0' 'comment/#0/start' '#' kdb meta-set 'user:/tests/storage/array/#0' 'comment/#0/space' '4'
kdb meta-set 'user:/tests/storage/array/#0' 'comment/#1' ' Comment preceding the first element' kdb meta-set 'user:/tests/storage/array/#0' 'comment/#1/start' '#' kdb meta-set 'user:/tests/storage/array/#0' 'comment/#1/space' '4'
kdb meta-set 'user:/tests/storage/array/#0' 'comment/#2' ' Another comment preceding the first element' kdb meta-set 'user:/tests/storage/array/#0' 'comment/#2/start' '#' kdb meta-set 'user:/tests/storage/array/#0' 'comment/#2/space' '6'
kdb meta-set 'user:/tests/storage/array/#1' 'comment/#0' ' Inline comment of second element' kdb meta-set 'user:/tests/storage/array/#1' 'comment/#0/start' '#' kdb meta-set 'user:/tests/storage/array/#1' 'comment/#0/space' '4'
kdb meta-set 'user:/tests/storage/array/#1' 'comment/#1' ' Comment preceding the second element' kdb meta-set 'user:/tests/storage/array/#1' 'comment/#1/start' '#' kdb meta-set 'user:/tests/storage/array/#1' 'comment/#1/space' '6'
kdb meta-set 'user:/tests/storage/array/#2' 'comment/#0' ' Inline comment of the last element' kdb meta-set 'user:/tests/storage/array/#2' 'comment/#0/start' '#' kdb meta-set 'user:/tests/storage/array/#2' 'comment/#0/space' '5'
cat kdb file user:/tests/storage
#> array = [ # Comment preceding the first element #> # Another comment preceding the first element #> 1, # Inline comment of first element #> # Comment preceding the second element #> 2, # Inline comment of second element #> 3 # Inline comment of the last element #> ] # Inline comment after the array
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage
sudo kdb mount test_order.toml user:/tests/storage toml type
kdb set 'user:/tests/storage/common/c' '0' kdb set 'user:/tests/storage/common/b' '1' kdb set 'user:/tests/storage/common/a' '2' kdb set 'user:/tests/storage/d' '3'
cat kdb file user:/tests/storage
#> common.c = 0 #> common.b = 1 #> common.a = 2 #> d = 3
kdb meta-set 'user:/tests/storage/common' 'tomltype' 'simpletable'
cat kdb file user:/tests/storage
#> d = 3 #> [common] #> c = 0 #> b = 1 #> a = 2
kdb rm -r user:/tests/storage sudo kdb umount user:/tests/storage ```
In this example, d
and common
have the same parent, the file root. This means, they need to be sorted with each other. d
would be placed before common
by it's order, since it was set before, and thus, has lesser order. However, their order never gets compared, since common
is a simple table and d
is not, so d
will get sorted before the table regardless of order.
While the plugin has good capabilities in handling the TOML file format, it currently lacks some features possible with Elektra:
Additionally, there are some minor limitations related to the TOML file format, mostly related to the preservation of the original file structure: