Add support for executing RPCs
Creating a temporary YangAccess for RPC input means I need to somehow
give the right libyang schemas. For that reason I supply a callable
which is able to fetch the schema and create a YangAccess instance for
ProxyDatastore.
The ProxyDatastore class now has a simple mechanism for deciding whether
to use the normal datastore and the temporary based on a path prefix.
Change-Id: Ib455f53237598bc2620161a44fb89c48ddfeb6e3
diff --git a/src/cli.cpp b/src/cli.cpp
index 1f62f78..a539b90 100644
--- a/src/cli.cpp
+++ b/src/cli.cpp
@@ -15,6 +15,7 @@
#include "proxy_datastore.hpp"
#if defined(SYSREPO_CLI)
#include "sysrepo_access.hpp"
+#include "yang_schema.hpp"
#define PROGRAM_NAME "sysrepo-cli"
static const auto usage = R"(CLI interface to sysrepo
@@ -124,7 +125,17 @@
#error "Unknown CLI backend"
#endif
- ProxyDatastore proxyDatastore(datastore);
+#if defined(SYSREPO_CLI)
+ auto createTemporaryDatastore = [](const std::shared_ptr<DatastoreAccess>& datastore) {
+ return std::make_shared<YangAccess>(std::static_pointer_cast<YangSchema>(datastore->schema()));
+ };
+#elif defined(YANG_CLI)
+ auto createTemporaryDatastore = [](const std::shared_ptr<DatastoreAccess>&) {
+ return nullptr;
+ };
+#endif
+
+ ProxyDatastore proxyDatastore(datastore, createTemporaryDatastore);
auto dataQuery = std::make_shared<DataQuery>(*datastore);
Parser parser(datastore->schema(), writableOps, dataQuery);
@@ -189,6 +200,8 @@
std::cerr << ex.what() << std::endl;
} catch (DatastoreException& ex) {
std::cerr << ex.what() << std::endl;
+ } catch (std::runtime_error& ex) {
+ std::cerr << ex.what() << std::endl;
}
lineEditor.history_add(line);