show keys of lists in the prompt
Change-Id: I29deb2b3aa80734b675c0c8309f785fa2eed7ccc
diff --git a/src/main.cpp b/src/main.cpp
index c40f2ae..3a66ee4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -62,7 +62,7 @@
Parser parser(schema);
while (true) {
- std::cout << parser.currentNode() << ">";
+ std::cout << parser.currentNode() << "> ";
std::string input;
std::getline(std::cin, input);
if (std::cin.eof())
diff --git a/src/parser.cpp b/src/parser.cpp
index 87ed317..b8ac30d 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -5,6 +5,7 @@
* Written by Václav Kubernát <kubervac@fit.cvut.cz>
*
*/
+#include <experimental/iterator>
#include <ostream>
#include "parser.hpp"
@@ -18,6 +19,28 @@
{
}
+struct nodeToDataString : public boost::static_visitor<std::string> {
+ std::string operator()(const listElement_& node) const
+ {
+ std::ostringstream res;
+ res << node.m_name + "[";
+ std::transform(node.m_keys.begin(), node.m_keys.end(),
+ std::experimental::make_ostream_joiner(res, ' '),
+ [] (const auto& it) { return it.first + "=" + it.second; });
+ res << "]";
+ return res.str();
+ }
+ std::string operator()(const nodeup_&) const
+ {
+ return "..";
+ }
+ template <class T>
+ std::string operator()(const T& node) const
+ {
+ return node.m_name;
+ }
+};
+
cd_ Parser::parseCommand(const std::string& line, std::ostream& errorStream)
{
cd_ parsedCommand;
@@ -53,7 +76,7 @@
{
std::string res;
for (const auto& it : m_curDir.m_nodes) {
- res = joinPaths(res, boost::apply_visitor(nodeToString(), it));
+ res = joinPaths(res, boost::apply_visitor(nodeToDataString(), it));
}
return res;
diff --git a/src/schema.cpp b/src/schema.cpp
index aaaab8b..1760b5d 100644
--- a/src/schema.cpp
+++ b/src/schema.cpp
@@ -12,12 +12,23 @@
InvalidNodeException::~InvalidNodeException() = default;
+struct nodeToSchemaString : public boost::static_visitor<std::string> {
+ std::string operator()(const nodeup_&) const
+ {
+ return "..";
+ }
+ template <class T>
+ std::string operator()(const T& node) const
+ {
+ return node.m_name;
+ }
+};
std::string pathToString(const path_& path)
{
std::string res;
for (const auto it : path.m_nodes)
- res = joinPaths(res, boost::apply_visitor(nodeToString(), it));
+ res = joinPaths(res, boost::apply_visitor(nodeToSchemaString(), it));
return res;
}
diff --git a/src/schema.hpp b/src/schema.hpp
index a414dc9..7d6e486 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -22,17 +22,7 @@
};
}
-struct nodeToString : public boost::static_visitor<std::string> {
- std::string operator()(const nodeup_&) const
- {
- return "..";
- }
- template <class T>
- std::string operator()(const T& node) const
- {
- return node.m_name;
- }
-};
+
using NodeType = boost::variant<yang::container, yang::list>;