Elektra
0.8.23
|
The โmaybe this is not INIโ plugin (mini
) is a very simple storage plugin loosely based on the INI file format. Since this plugin does not support sections it might be more appropriate to say that it is based on the .properties format, used in many Java applications.
The following example shows basic usage of the mini
plugin.
`` <h1>Mount mini plugin to cascading namespace
/examples/mini` sudo kdb mount mini.ini /examples/mini mini
kdb set /examples/mini/key value #> Using name user/examples/mini/key #> Create a new key user/examples/mini/key with string "value" kdb set /examples/mini/mi/mi/mr beaker #> Using name user/examples/mini/mi/mi/mr #> Create a new key user/examples/mini/mi/mi/mr with string "beaker"
kdb export /examples/mini mini #> key=value #> mi/mi/mr=beaker
echo "๐ = ๐ฆ" >> kdb file /examples/mini
echo "level1/level2 = ๐พ" >> kdb file /examples/mini
/examples/mini
contains four key value pairskdb ls /examples/mini #> user/examples/mini/key #> user/examples/mini/level1/level2 #> user/examples/mini/mi/mi/mr #> user/examples/mini/๐
/examples/mini/๐
contains the correct valuekdb get "/examples/mini/๐" #> ๐ฆ
kdb rm -r /examples/mini sudo kdb umount /examples/mini ```
As with most configuration file formats, some characters carry special meaning. In the case of the mini
plugin that character are
=
sign, which separates keys from values and#
and ;
, the characters that denote a comment.In case of key values you do not need to care about the special meaning of these characters most of the time, since the plugin handles escaping and unescaping of them for you. Since mINI use the backslash character (\
) to escape values, the backspace character will be escaped too (\\
). The following example shows the escaping behavior.
``` sudo kdb mount mini.ini /examples/mini mini
kdb set /examples/mini/key ';#=\' #> Using name user/examples/mini/key #> Create a new key user/examples/mini/key with string ";#=\"
kdb file /examples/mini | xargs cat #> key=\;#\=\
kdb get /examples/mini/key #> ;#=\
;
and #
characters, then theyecho 'background = #0F0F0F ; Background color' >> kdb file /examples/mini
echo 'foreground = #FFFFFF # Foreground color' >> kdb file /examples/mini
kdb get /examples/mini/background #> #0F0F0F kdb get /examples/mini/foreground #> #FFFFFF
kdb rm -r /examples/mini sudo kdb umount /examples/mini ```
In the case of key names you must not use any of the characters mentioned above (;
, #
and =
) at all. Otherwise the behavior of the plugin will be undefined.
This plugin only supports simple key-value based properties files without sections. mINI also does not support metadata. If you want a more feature complete plugin, then please take a look at the ini plugin. The example below shows some of the limitations of the plugin.
``` sudo kdb mount mini.ini /examples/mini mini
echo '[section]' >> kdb file /examples/mini
printf 'key="multi\nline"' >> kdb file /examples/mini
key
, sincekdb ls /examples/mini 2> stderr.txt #> user/examples/mini/key
cat stderr.txt | grep 'Reason:' | sed 's/^[[:space:]]*//' #> Reason: Line 1: โ[section]โ is not a valid key value pair #> Reason: Line 3: โline"โ is not a valid key value pair
ini
and ni
plugin, mINI does not support metadata.kdb lsmeta /examples/mini
key
also contains the double quote symbol, since mINI doeskdb get /examples/mini/key #> "multi
rm stderr.txt kdb rm -r /examples/mini sudo kdb umount /examples/mini ```