add a basic interpreter for cd

Change-Id: Ibd89705142715864f2fec4f4c157f99fcb2ae505
diff --git a/src/CTree.cpp b/src/CTree.cpp
index cc014dc..5d0cf7e 100644
--- a/src/CTree.cpp
+++ b/src/CTree.cpp
@@ -12,6 +12,13 @@
 
 InvalidNodeException::~InvalidNodeException() = default;
 
+struct nodeToString : public boost::static_visitor<std::string> {
+    template <class T>
+    std::string operator()(const T& node) const
+    {
+        return node.m_name;
+    }
+};
 
 
 CTree::CTree()
@@ -88,13 +95,15 @@
 }
 
 
-void CTree::changeNode(const std::string& name)
+void CTree::changeNode(const path_& name)
 {
-    if (name.empty()) {
+    if (name.m_nodes.empty()) {
         m_curDir = "";
         return;
     }
-    m_curDir += joinPaths(m_curDir, name);
+    for (const auto& it : name.m_nodes) {
+        m_curDir = joinPaths(m_curDir, boost::apply_visitor(nodeToString(), it));
+    }
 }
 std::string CTree::currentNode() const
 {
diff --git a/src/CTree.hpp b/src/CTree.hpp
index 3e95066..6fe54d8 100644
--- a/src/CTree.hpp
+++ b/src/CTree.hpp
@@ -12,6 +12,7 @@
 #include <set>
 #include <stdexcept>
 #include <unordered_map>
+#include "ast.hpp"
 
 namespace schema {
     struct container {
@@ -48,7 +49,7 @@
     bool listHasKey(const std::string& location, const std::string& name, const std::string& key) const;
     bool isList(const std::string& location, const std::string& name) const;
     void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys);
-    void changeNode(const std::string& name);
+    void changeNode(const path_& name);
     std::string currentNode() const;
 
 private:
diff --git a/src/main.cpp b/src/main.cpp
index 7e6d5f1..68ddbef 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -35,12 +35,9 @@
 using x3::lexeme;
 using ascii::space;
 
-
-std::string getInput()
+void interpret(cd_ command, CTree& tree)
 {
-    std::string line;
-    std::getline(std::cin, line);
-    return line;
+    tree.changeNode(command.m_path);
 }
 
 int main(int argc, char* argv[])
@@ -51,5 +48,33 @@
                                "netconf-cli " NETCONF_CLI_VERSION,
                                true);
     std::cout << "Welcome to netconf-cli" << std::endl;
+
+    CTree tree;
+    tree.addContainer("", "a");
+    tree.addContainer("", "b");
+    tree.addContainer("a", "a2");
+    tree.addContainer("b", "b2");
+    tree.addContainer("a/a2", "a3");
+    tree.addContainer("b/b2", "b3");
+    tree.addList("", "list", {"number"});
+    tree.addContainer("list", "contInList");
+    tree.addList("", "twoKeyList", {"number", "name"});
+    CParser parser(tree);
+
+    while (true) {
+        std::cout << tree.currentNode() << ">";
+        std::string input;
+        std::getline(std::cin, input);
+        if (std::cin.eof())
+            break;
+
+        try {
+            cd_ command = parser.parseCommand(input, std::cout);
+            interpret(command, tree);
+        } catch (InvalidCommandException& ex) {
+            std::cerr << ex.what() << std::endl;
+        }
+    }
+
     return 0;
 }