diff --git a/doc/man1/flux-kvs.adoc b/doc/man1/flux-kvs.adoc index ffb4e9877124..cb1952dd149a 100644 --- a/doc/man1/flux-kvs.adoc +++ b/doc/man1/flux-kvs.adoc @@ -50,13 +50,15 @@ interpreted as encoded JSON and formatted accordingly. If '-r', value is displayed without a newline. If '-t', the RFC 11 object is displayed. '-a treeobj' causes the lookup to be relative to an RFC 11 snapshot reference. -*put* [-j|-r|-t] [-n] 'key=value' ['key=value...']:: +*put* [-j|-r|-t] [-n] [-A] 'key=value' ['key=value...']:: Store 'value' under 'key' and commit it. If it already has a value, overwrite it. If no options, value is stored directly. If '-j', it is first encoded as JSON, then stored. If '-r', the value may be read from standard input if specified as "-", and may include embedded NULL bytes. If '-t', value is stored as a RFC 11 object. '-n' prevents the commit -from being merged with with other contemporaneous commits. +from being merged with with other contemporaneous commits. '-A' appends the +value to a key instead of overwriting the value. Append is incompatible with +the -j option. *ls* [-R] [-d] [-F] [-w COLS] [-1] ['key' ...]:: Display directory referred to by _key_, or "." (root) if unspecified. diff --git a/src/cmd/flux-kvs.c b/src/cmd/flux-kvs.c index 80313f6be1cd..471bbb8eb6f0 100644 --- a/src/cmd/flux-kvs.c +++ b/src/cmd/flux-kvs.c @@ -94,6 +94,9 @@ static struct optparse_option put_opts[] = { { .name = "no-merge", .key = 'n', .has_arg = 0, .usage = "Set the NO_MERGE flag to ensure commit is standalone", }, + { .name = "append", .key = 'A', .has_arg = 0, + .usage = "Append value(s) to key instead of overwriting", + }, OPTPARSE_TABLE_END }; @@ -498,6 +501,7 @@ int cmd_put (optparse_t *p, int argc, char **argv) flux_future_t *f; flux_kvs_txn_t *txn; int commit_flags = 0; + int put_flags = 0; optindex = optparse_option_index (p); if ((optindex - argc) == 0) { @@ -534,18 +538,25 @@ int cmd_put (optparse_t *p, int argc, char **argv) else if (optparse_hasopt (p, "raw")) { int len; uint8_t *buf = NULL; + + if (optparse_hasopt (p, "append")) + put_flags |= FLUX_KVS_APPEND; + if (!strcmp (val, "-")) { // special handling for "--raw key=-" if ((len = read_all (STDIN_FILENO, &buf)) < 0) log_err_exit ("stdin"); val = (char *)buf; } else len = strlen (val); - if (flux_kvs_txn_put_raw (txn, 0, key, val, len) < 0) + if (flux_kvs_txn_put_raw (txn, put_flags, key, val, len) < 0) log_err_exit ("%s", key); free (buf); } else { - if (flux_kvs_txn_put (txn, 0, key, val) < 0) + if (optparse_hasopt (p, "append")) + put_flags |= FLUX_KVS_APPEND; + + if (flux_kvs_txn_put (txn, put_flags, key, val) < 0) log_err_exit ("%s", key); } free (key);