Move ls logic to Interpreter
Change-Id: I9d1e04573be5d7701e4e66e53aefb9dc1a1fd8ab
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index 8f419c3..9912584 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -76,7 +76,26 @@
recursion = Recursion::Recursive;
}
- for (const auto& it : m_parser.availableNodes(ls.m_path, recursion))
+ std::set<std::string> toPrint;
+
+ auto pathArg = dataPathToSchemaPath(m_parser.currentPath());
+ if (ls.m_path) {
+ if (ls.m_path->type() == typeid(module_)) {
+ toPrint = m_datastore.schema()->availableNodes(*ls.m_path, recursion);
+ } else {
+ auto schemaPath = anyPathToSchemaPath(*ls.m_path);
+ if (schemaPath.m_scope == Scope::Absolute) {
+ pathArg = schemaPath;
+ } else {
+ pathArg.m_nodes.insert(pathArg.m_nodes.end(), schemaPath.m_nodes.begin(), schemaPath.m_nodes.end());
+ }
+ toPrint = m_datastore.schema()->availableNodes(pathArg, recursion);
+ }
+ } else {
+ toPrint = m_datastore.schema()->availableNodes(pathArg, recursion);
+ }
+
+ for (const auto& it : toPrint)
std::cout << it << std::endl;
}
diff --git a/src/parser.cpp b/src/parser.cpp
index 245de1d..2942d56 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -101,20 +101,7 @@
return pathToDataString(m_curDir, Prefixes::WhenNeeded);
}
-std::set<std::string> Parser::availableNodes(const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path, const Recursion& option) const
+dataPath_ Parser::currentPath()
{
- auto pathArg = dataPathToSchemaPath(m_curDir);
- if (path) {
- if (path->type() == typeid(module_)) {
- return m_schema->availableNodes(*path, option);
- }
-
- auto schemaPath = anyPathToSchemaPath(*path);
- if (schemaPath.m_scope == Scope::Absolute) {
- pathArg = schemaPath;
- } else {
- pathArg.m_nodes.insert(pathArg.m_nodes.end(), schemaPath.m_nodes.begin(), schemaPath.m_nodes.end());
- }
- }
- return m_schema->availableNodes(pathArg, option);
+ return m_curDir;
}
diff --git a/src/parser.hpp b/src/parser.hpp
index 82e7daf..14daa9e 100644
--- a/src/parser.hpp
+++ b/src/parser.hpp
@@ -37,8 +37,8 @@
command_ parseCommand(const std::string& line, std::ostream& errorStream);
void changeNode(const dataPath_& name);
std::string currentNode() const;
- std::set<std::string> availableNodes(const boost::optional<boost::variant<dataPath_, schemaPath_, module_>>& path, const Recursion& option) const;
Completions completeCommand(const std::string& line, std::ostream& errorStream) const;
+ dataPath_ currentPath();
private:
const std::shared_ptr<const Schema> m_schema;