From e0ff5275c4d871a86c4c06b128b4e469fca56b5c 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 5ee201fd..cf21c17f 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 "<