Make main take schema arguments
The main executable now parses YANG schemas as command line arguments
and also sets the search dirs to where the files are located.
Change-Id: I0141ed0330038ba46ae49aa75c44da4af833d40c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4e09b90..0db1e2c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -85,6 +85,12 @@
src/main.cpp
)
target_link_libraries(netconf-cli yangschema docopt parser)
+if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+")
+ target_link_libraries(netconf-cli c++experimental)
+else()
+ target_link_libraries(netconf-cli stdc++fs)
+endif()
+
add_dependencies(netconf-cli target-NETCONF_CLI_VERSION)
target_include_directories(netconf-cli PRIVATE ${PROJECT_BINARY_DIR})
diff --git a/src/main.cpp b/src/main.cpp
index 5bf4600..2358dff 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,17 +7,18 @@
*/
#include <docopt.h>
+#include <experimental/filesystem>
#include <iostream>
#include "NETCONF_CLI_VERSION.h"
#include "interpreter.hpp"
-#include "static_schema.hpp"
+#include "yang_schema.hpp"
static const char usage[] =
R"(CLI interface to remote NETCONF hosts
Usage:
- netconf-cli
+ netconf-cli <path-to-yang-schema>...
netconf-cli (-h | --help)
netconf-cli --version
)";
@@ -32,19 +33,15 @@
true);
std::cout << "Welcome to netconf-cli" << std::endl;
- auto yangschema = std::make_shared<StaticSchema>();
- yangschema->addModule("mod");
- yangschema->addContainer("", "mod:a", yang::ContainerTraits::Presence);
- yangschema->addContainer("", "mod:b");
- yangschema->addContainer("mod:a", "mod:a2", yang::ContainerTraits::Presence);
- yangschema->addContainer("mod:b", "mod:b2");
- yangschema->addContainer("mod:a/mod:a2", "mod:a3");
- yangschema->addContainer("mod:b/mod:b2", "mod:b3");
- yangschema->addList("", "mod:list", {"number"});
- yangschema->addContainer("mod:list", "contInList");
- yangschema->addList("", "mod:twoKeyList", {"number", "name"});
+ auto yangschema = std::make_shared<YangSchema>();
Parser parser(yangschema);
+ for (auto it : args.at("<path-to-yang-schema>").asStringList()) {
+ auto dir = std::experimental::filesystem::absolute(it).remove_filename();
+ yangschema->addSchemaDirectory(dir.c_str());
+ yangschema->addSchemaFile(it.c_str());
+ }
+
while (true) {
std::cout << parser.currentNode() << "> ";
std::string input;