Tie datastore to the interpreter
Change-Id: I943b071981aa0e16dcc32d1c87cebb15846f7d7e
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index f71c12f..24c48c4 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -7,6 +7,7 @@
*/
#include <iostream>
+#include "datastore_access.hpp"
#include "interpreter.hpp"
struct leafDataToString : boost::static_visitor<std::string> {
@@ -25,7 +26,7 @@
void Interpreter::operator()(const set_& set) const
{
- std::cout << "Setting " << pathToDataString(set.m_path) << " to " << boost::apply_visitor(leafDataToString(), set.m_data) << std::endl;
+ m_datastore.setLeaf(absolutePathFromCommand(set), set.m_data);
}
void Interpreter::operator()(const cd_& cd) const
@@ -35,14 +36,12 @@
void Interpreter::operator()(const create_& create) const
{
- auto cont = boost::get<container_>(create.m_path.m_nodes.back().m_suffix);
- std::cout << "Presence container " << cont.m_name << " created." << std::endl;
+ m_datastore.createPresenceContainer(absolutePathFromCommand(create));
}
void Interpreter::operator()(const delete_& delet) const
{
- auto cont = boost::get<container_>(delet.m_path.m_nodes.back().m_suffix);
- std::cout << "Presence container " << cont.m_name << " deleted." << std::endl;
+ m_datastore.deletePresenceContainer(absolutePathFromCommand(delet));
}
void Interpreter::operator()(const ls_& ls) const
@@ -53,7 +52,13 @@
std::cout << it << std::endl;
}
-Interpreter::Interpreter(Parser& parser, Schema&)
- : m_parser(parser)
+template <typename T>
+std::string Interpreter::absolutePathFromCommand(const T& command) const
+{
+ return joinPaths(m_parser.currentNode(), pathToDataString(command.m_path));
+}
+
+Interpreter::Interpreter(Parser& parser, DatastoreAccess& datastore)
+ : m_parser(parser), m_datastore(datastore)
{
}
diff --git a/src/interpreter.hpp b/src/interpreter.hpp
index 8acf8bd..87f12f1 100644
--- a/src/interpreter.hpp
+++ b/src/interpreter.hpp
@@ -10,9 +10,10 @@
#include <boost/variant/static_visitor.hpp>
#include "parser.hpp"
+#include "datastore_access.hpp"
struct Interpreter : boost::static_visitor<void> {
- Interpreter(Parser& parser, Schema&);
+ Interpreter(Parser& parser, DatastoreAccess& datastore);
void operator()(const set_&) const;
void operator()(const cd_&) const;
@@ -21,5 +22,9 @@
void operator()(const ls_&) const;
private:
+ template <typename T>
+ std::string absolutePathFromCommand(const T& command) const;
+
Parser& m_parser;
+ DatastoreAccess& m_datastore;
};
diff --git a/src/main.cpp b/src/main.cpp
index 2358dff..73e39a6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,6 +11,7 @@
#include <iostream>
#include "NETCONF_CLI_VERSION.h"
#include "interpreter.hpp"
+#include "sysrepo_access.hpp"
#include "yang_schema.hpp"
@@ -36,6 +37,8 @@
auto yangschema = std::make_shared<YangSchema>();
Parser parser(yangschema);
+ SysrepoAccess datastore("netconf-cli");
+
for (auto it : args.at("<path-to-yang-schema>").asStringList()) {
auto dir = std::experimental::filesystem::absolute(it).remove_filename();
yangschema->addSchemaDirectory(dir.c_str());
@@ -51,7 +54,7 @@
try {
command_ cmd = parser.parseCommand(input, std::cout);
- boost::apply_visitor(Interpreter(parser, *yangschema), cmd);
+ boost::apply_visitor(Interpreter(parser, datastore), cmd);
} catch (InvalidCommandException& ex) {
std::cerr << ex.what() << std::endl;
}