/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvxs is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include #include #include #include #define PVXS_ENABLE_EXPERT_API #include #include #include #include "utilpvt.h" #include "evhelper.h" #include "cliutil.h" #ifndef REALMAIN # define REALMAIN main #endif using namespace pvxs; namespace { void usage(const char* argv0) { std::cerr<<"Usage: "< [ | = ...]\n" "\n" " -h Show this message.\n" " -V Print version and exit.\n" " -r pvRequest condition.\n" " -v Make more noise.\n" " -d Shorthand for $PVXS_LOG=\"pvxs.*=DEBUG\". Make a lot of noise.\n" " -w Operation timeout in seconds. default 5 sec.\n" ; } } // namespace int REALMAIN(int argc, char *argv[]) { try { logger_config_env(); // from $PVXS_LOG double timeout = 5.0; bool verbose = false; std::string request; GetOpt opts(argc, argv, "hvVdw:r:"); for(auto& pair : opts.arguments) { switch(pair.first) { case 'h': usage(opts.argv0); return 0; case 'V': std::cout<(); break; case 'r': request = *pair.second; break; default: usage(opts.argv0); std::cerr<<"\nUnknown argument: "< values; if(opts.positional.size()==2 && std::string(opts.positional[1]).find_first_of('=')==std::string::npos) { // only one field assignment, and field name omitted. // if JSON map, treat as entire struct. Others imply .value const auto& sval = opts.positional[1]; values[sval[0]=='{' ? "" : "value"] = sval; } else { for(auto n : range(size_t(1), opts.positional.size())) { std::string fv(opts.positional[n]); auto sep = fv.find_first_of('='); if(sep==std::string::npos) { std::cerr<= not \""< Value { auto val = std::move(prototype); // clear all defined fields, but retain "current" values for NTEnum lookup. val.unmark(false, true); for(auto& pair : values) { try{ auto fld(val); if(!pair.first.empty()) fld = val.lookup(pair.first); auto& sv(pair.second); if(!sv.empty() && (sv[0]=='{' || sv[0]=='[' || sv[0]=='"')) json::Parse(pair.second).into(fld); else fld.from(sv); }catch(std::exception& e){ throw std::runtime_error(SB()<<"Unable to assign "<