Add get command
Change-Id: Id06539070fb8d815786149e1479e93d75d4b70f1
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index b919786..4e5d665 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -34,6 +34,14 @@
m_datastore.setLeaf(absolutePathFromCommand(set), set.m_data);
}
+void Interpreter::operator()(const get_& get) const
+{
+ auto items = m_datastore.getItems(absolutePathFromCommand(get));
+ for (auto it : items) {
+ std::cout << it.first << " = " << boost::apply_visitor(leafDataToString(), it.second) << std::endl;
+ }
+}
+
void Interpreter::operator()(const cd_& cd) const
{
m_parser.changeNode(cd.m_path);
@@ -66,6 +74,17 @@
return joinPaths(m_parser.currentNode(), pathToDataString(command.m_path));
}
+std::string Interpreter::absolutePathFromCommand(const get_& get) const
+{
+ if (!get.m_path) {
+ return m_parser.currentNode();
+ } else if (get.m_path->m_scope == Scope::Absolute) {
+ return "/" + pathToDataString(*get.m_path);
+ } else {
+ return joinPaths(m_parser.currentNode(), pathToDataString(*get.m_path));
+ }
+}
+
Interpreter::Interpreter(Parser& parser, DatastoreAccess& datastore)
: m_parser(parser)
, m_datastore(datastore)