global-functions: $ParseKeyValueStore: support JSON as input

This used to require a key=value store, separated with commas. An
example for `netwatch-notify` is:

    /tool/netwatch/add comment="notify, name=example.com" host=93.184.215.14;

Now JSON is supported as well, so you could use:

    /tool/netwatch/add comment="{\"notify\":true,\"name\":\"example.com\"}" host=93.184.215.14;

Looks more clumsy here, but may be of help in more complex setups...
This commit is contained in:
Christian Hesse 2024-12-25 22:22:30 +01:00
parent 8212bd6c95
commit ef3ce7cc6c

View file

@ -919,6 +919,13 @@
# parse key value store
:set ParseKeyValueStore do={
:local Source $1;
:if ([ :pick $Source 0 1 ] = "{") do={
:do {
:return [ :deserialize from=json $Source ];
} on-error={ }
}
:if ([ :typeof $Source ] != "array") do={
:set Source [ :tostr $1 ];
}