From 595bb27721f65ed647c39eadad363bc260efb791 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 19 Nov 2023 14:41:09 -0800 Subject: [PATCH] pvxput handle JSON --- tools/put.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/put.cpp b/tools/put.cpp index 5ee201fda..cf21c17f5 100644 --- a/tools/put.cpp +++ b/tools/put.cpp @@ -14,6 +14,7 @@ #include #include +#include #include "utilpvt.h" #include "evhelper.h" @@ -85,9 +86,10 @@ int main(int argc, char *argv[]) if(argc-optind==1 && std::string(argv[optind]).find_first_of('=')==std::string::npos) { // only one field assignment, and field name omitted. - // implies .value + // if JSON map, treat as entire struct. Others imply .value - values["value"] = argv[optind]; + auto sval(argv[optind]); + values[sval[0]=='{' ? "" : "value"] = sval; } else { for(auto n : range(optind, argc)) { @@ -118,9 +120,18 @@ int main(int argc, char *argv[]) auto val = std::move(prototype); for(auto& pair : values) { try{ - val[pair.first] = pair.second; - }catch(NoConvert& e){ - throw std::runtime_error(SB()<<"Unable to assign "<