Skip to content

Commit

Permalink
admin: Add local cells to for \c tab completion
Browse files Browse the repository at this point in the history
When connected to some cell, the local cells of that domain are now considered
for tab completion too. This means that if you connect to, eg, a System cell,
you can tab complete to other cells in that domain. Same is true if you connect
to an FTP door: now you can tab complete to the child doors too.

Tab completion has no idea about whether any of those local cells are well-known
and thus well-known cells will appear twice in the list (once without a domain
suffix and once with a domain suffix).

Target: trunk
Require-notes: yes
Require-book: no
Acked-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
Patch: https://rb.dcache.org/r/7888/
  • Loading branch information
gbehrmann committed Mar 5, 2015
1 parent 662cece commit cdd008d
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -252,8 +252,7 @@ private List<String> expandCellPatterns(List<String> patterns)
List<ListenableFuture<List<String>>> futures = new ArrayList<>();
for (String pattern : patterns) {
String[] s = pattern.split("@", 2);
Predicate<String> matchesCellName =
s[0].isEmpty() ? (String) -> true : parseGlobToPattern(s[0]).asPredicate();
Predicate<String> matchesCellName = toGlobPredicate(s[0]);
if (s.length == 1) {
/* Add matching well-known cells. */
domains.values().stream()
Expand All @@ -266,8 +265,7 @@ private List<String> expandCellPatterns(List<String> patterns)
} else {
/* Query the cells of each matching domain.
*/
Predicate<String> matchesDomainName =
s[1].isEmpty() ? (String) -> true : parseGlobToPattern(s[1]).asPredicate();
Predicate<String> matchesDomainName = toGlobPredicate(s[1]);
domains.keySet().stream()
.filter(matchesDomainName)
.sorted(CASE_INSENSITIVE_ORDER)
Expand All @@ -280,6 +278,11 @@ private List<String> expandCellPatterns(List<String> patterns)
return allAsList(futures).get().stream().flatMap(Collection::stream).collect(toList());
}

private Predicate<String> toGlobPredicate(String s)
{
return s.isEmpty() ? (String) -> true : parseGlobToPattern(s).asPredicate();
}


public String getHello(){
return "dCache (" + Version.of(UserAdminShell.class).getVersion() + ")\n" + "Type \"\\?\" for help.\n";
Expand Down Expand Up @@ -1405,6 +1408,11 @@ private int completeShell(String buffer, int cursor, List<CharSequence> candidat
return -1;
}
candidates.addAll(expandCellPatterns(Collections.singletonList(command[1] + "*")));
if (!command[1].contains("@") && _currentPosition != null) {
/* Add local cells in the connected domain too. */
candidates.addAll(
getCells(_currentPosition.remote.getCellDomainName(), toGlobPredicate(command[1] + "*")).get());
}
return command[0].length() + 1;
case "\\sp":
return completeShell("PoolManager", command[0], command[1], cursor, candidates);
Expand Down

0 comments on commit cdd008d

Please sign in to comment.