Skip to content

Commit 3a890a8

Browse files
polycubed: fix list autocompletion
List autocompletion was partially broken because a look up with the wrong key name was done. This commit also adds some logic to avoid suggesting the "add", "del", "show" commands when in the middle of a list completion. ex: polycubectl cube_name complex_list key1 <tab>: suggest list of key2 for elements that also matchs key1. Fixes: 95aa741 ("implement bash autocompletion") Signed-off-by: Mauricio Vasquez B <mauriciovasquezbernal@gmail.com>
1 parent 8af01d1 commit 3a890a8

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/polycubed/src/server/Resources/Endpoint/ListResource.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ Response ListResource::Completion(const std::string &cube_name, HelpType type,
327327

328328
auto size_keys = list_keys.size();
329329
std::string keyname = keys_[size_keys].Name();
330+
std::string original_keyname = keys_[size_keys].OriginalName();
330331

331332
nlohmann::json val = nlohmann::json::array();
332333

@@ -349,7 +350,7 @@ Response ListResource::Completion(const std::string &cube_name, HelpType type,
349350
}
350351

351352
if (found) {
352-
val += item.at(keyname);
353+
val += item.at(original_keyname);
353354
}
354355
}
355356

@@ -359,11 +360,14 @@ Response ListResource::Completion(const std::string &cube_name, HelpType type,
359360
case HelpType::DEL:
360361
break;
361362
case HelpType::NONE:
362-
if (configuration_) {
363-
val += "add";
364-
val += "del";
363+
// suggest these commands only if we are not in the middle of a list
364+
if (list_keys.size() == 0) {
365+
if (configuration_) {
366+
val += "add";
367+
val += "del";
368+
}
369+
val += "show";
365370
}
366-
val += "show";
367371
break;
368372
default:
369373
return {kBadRequest, nullptr};

0 commit comments

Comments
 (0)