libelektra
libelektra copied to clipboard
KDB Command to Add Array Values
Description
Currently we have to set array keys using the syntax array/#number_of_entry
:
kdb set user/array
kdb set user/array/#0 "first element"
kdb set user/array/#1 "second element"
kdb ls user/array
#> user/array
#> user/array/#0
#> user/array/#1
. This works, but if we want to add something at the last place of the array we have to know the last index. It might make sense to add a new command to kdb
that adds a value at the last position of an array. The syntax of the command could look something like this:
kdb add user/array "third element"
kdb ls user/array
#> user/array
#> user/array/#0
#> user/array/#1
#> user/array/#2
kdb add user/newarray "No 1"
kdb ls user/newarray
#> user/newarray
#> user/newarray/#0
kdb get user/newarray/#0
#> No 1
. If we add such an command, then we should probably address issue #182 first.
Thank you for the feature request! I agree it would be very handy. It is already implemented in Ruby (for Puppet integration), but it is missing in the command-line interface.
I think there is no problem in using a higher-level languages or scripts for such convenience commands.
Btw. in doc/todo/TOOLS Line 88 such a tool is already proposed, but your examples are much clearer. I think, however, we should consider to use less generic names ("add" could be anything, see also #265).
I think, however, we should consider to use less generic names ("add" could be anything, see also #265).
How about kdb append
then? Another option might be kdb list add
, but unfortunately kdb list
is already taken. We could rename the current command list
to list-plugins
though.
What about setarray? (or array-set conforming to #265) array-add or array-append, array is okay, too. "list" is as generic as "add", we should rather avoid it.
Shouldn't we provide a full set of array commands? (array-rm, array-ls, array-...)
What about setarray? (or array-set conforming to #265) array-add or array-append, array is okay, too.
Command | Rating |
---|---|
setarray | ★★⭐︎⭐︎⭐︎ |
array-set | ★★⭐︎⭐︎⭐︎ |
array-add | ★★★⭐︎⭐︎ |
array-append | ★★★⭐︎⭐︎ |
"list" is as generic as "add", we should rather avoid it.
Great, then let us rename kdb list
to kdb list-plugins
😊.
Shouldn't we provide a full set of array commands? (array-rm, array-ls, array-...)
Yes, that would be great and also why I suggested kdb list
. We could then add multiple commands like:
-
kdb list length
: Return the number of elements of an array -
kdb list append
: Add an element at the end of an array -
kdb list set
: Replace an array element at a certain position
. Replacing list
with array
in the commands above would be okay with me too.
We could then add multiple commands like
kdb list length
Currently we use "-" to form an hierarchy. This makes it easier to implement subcommands in different programming languages (e.g. scripts).
I mark this issue stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping the issue by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
I closed this issue now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
I closed this issue now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart: