Fix cd into leafs
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/173
Change-Id: I553c6d769204ebadc3625b9a3fc397adb64ca484
diff --git a/src/path_parser.hpp b/src/path_parser.hpp
index 3abbce3..20c48da 100644
--- a/src/path_parser.hpp
+++ b/src/path_parser.hpp
@@ -464,7 +464,9 @@
(module >> "*");
auto const cdPath_def =
- PathParser<PathParserMode::DataPath, CompletionMode::Data>{noRpcOrAction};
+ PathParser<PathParserMode::DataPath, CompletionMode::Data>{[] (const Schema& schema, const std::string& path) {
+ return noRpcOrAction(schema, path) && schema.nodeType(path) != yang::NodeTypes::Leaf;
+ }};
auto const presenceContainerPath_def =
dataPath;
diff --git a/tests/cd.cpp b/tests/cd.cpp
index 174ffd0..3e29d5a 100644
--- a/tests/cd.cpp
+++ b/tests/cd.cpp
@@ -33,6 +33,7 @@
schema->addRpc("/", "example:launch-nukes");
schema->addList("/", "example:ports", {"name"});
schema->addLeaf("/example:ports", "example:name", createEnum({"A", "B", "C"}));
+ schema->addLeaf("/", "example:myLeaf", yang::Int32{});
Parser parser(schema);
std::string input;
std::ostringstream errorStream;
@@ -330,6 +331,11 @@
input = "cd example:launch-nukes";
}
+ SECTION("cd into a leaf")
+ {
+ input = "cd example:myLeaf";
+ }
+
REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException);
}
}
diff --git a/tests/path_completion.cpp b/tests/path_completion.cpp
index 0585be0..4b6b25b 100644
--- a/tests/path_completion.cpp
+++ b/tests/path_completion.cpp
@@ -366,5 +366,12 @@
expectedContextLength = 0;
}
+ SECTION("leafs not completed for cd")
+ {
+ input = "cd ";
+ expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/","example:list", "example:ovoce", "example:ovocezelenina", "example:twoKeyList", "second:amelie/"};
+ expectedContextLength = 0;
+ }
+
REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
}