Fix get command completing nodes after list-end
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/159
Change-Id: Ib67436afa5d7e528a86e51ae6d73aa2affc8e36d
diff --git a/src/path_parser.hpp b/src/path_parser.hpp
index 6725831..eb34033 100644
--- a/src/path_parser.hpp
+++ b/src/path_parser.hpp
@@ -294,10 +294,15 @@
auto hasListEnd = incompleteDataNode<COMPLETION_MODE>{m_filterFunction}.parse(begin, end, ctx, rctx, attrNodeList);
if (hasListEnd) {
attrData.m_nodes.emplace_back(attrNodeList);
- // If the trailing slash matches, no more nodes are parsed.
- // That means no more completion. So, I generate them
- // manually.
- res = (-(trailingSlash >> x3::omit[pathCompletions<COMPLETION_MODE>{m_filterFunction}])).parse(begin, end, ctx, rctx, attrData.m_trailingSlash);
+ // If the trailing slash matches, no more nodes are parsed. That means no more completion. So, I
+ // generate them manually, but only if we're in AnyPath mode, so, for example, inside an `ls`
+ // command. If we're in DataPathListEnd it doesn't make sense to parse put any more nodes after the
+ // final list.
+ if constexpr (PARSER_MODE == PathParserMode::AnyPath) {
+ res = (-(trailingSlash >> x3::omit[pathCompletions<COMPLETION_MODE>{m_filterFunction}])).parse(begin, end, ctx, rctx, attrData.m_trailingSlash);
+ } else {
+ res = (-trailingSlash).parse(begin, end, ctx, rctx, attrData.m_trailingSlash);
+ }
}
}
}
diff --git a/tests/path_completion.cpp b/tests/path_completion.cpp
index bec663d..ffd3e93 100644
--- a/tests/path_completion.cpp
+++ b/tests/path_completion.cpp
@@ -195,6 +195,14 @@
expectedCompletions = {"listInCont"};
expectedContextLength = 1;
}
+
+ SECTION("get /example:list/")
+ {
+ input = "get /example:list/";
+ expectedCompletions = {};
+ // The expectedContextLength is 13, because the completion isn't actually generated after the slash.
+ expectedContextLength = 13;
+ }
}
SECTION("list keys completion")