diff --git a/modules/dcache/src/main/java/diskCacheV111/admin/HelpCompleter.java b/modules/dcache/src/main/java/diskCacheV111/admin/HelpCompleter.java
index 42fb52ecfc3..41d7081fa92 100644
--- a/modules/dcache/src/main/java/diskCacheV111/admin/HelpCompleter.java
+++ b/modules/dcache/src/main/java/diskCacheV111/admin/HelpCompleter.java
@@ -7,7 +7,7 @@
import jline.console.completer.Completer;
/**
- * Simple completor for JLine that uses the dCache help output to suggest command completions.
+ * Simple completer for JLine that uses the dCache help output to suggest command completions.
*/
public class HelpCompleter implements Completer {
@@ -21,8 +21,10 @@ public HelpCompleter(String help) {
}
protected String scan(String line) {
- int i = CharMatcher.anyOf("#[]<>|-").indexIn(line);
- return (i == -1) ? line : line.substring(0, i);
+ int i = CharMatcher.anyOf("#[]<>|").indexIn(line);
+ int j = line.indexOf(" -");
+ i = i == -1 || j == -1 ? Math.max(i, j) : Math.min(i, j);
+ return (i == -1) ? line : line.substring(0, i).trim();
}
@Override
diff --git a/modules/dcache/src/test/java/diskCacheV111/admin/HelpCompleterTest.java b/modules/dcache/src/test/java/diskCacheV111/admin/HelpCompleterTest.java
new file mode 100644
index 00000000000..43019e80c2f
--- /dev/null
+++ b/modules/dcache/src/test/java/diskCacheV111/admin/HelpCompleterTest.java
@@ -0,0 +1,49 @@
+/*
+ * dCache - http://www.dcache.org/
+ *
+ * Copyright (C) 2023 Deutsches Elektronen-Synchrotron
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package diskCacheV111.admin;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class HelpCompleterTest {
+
+ HelpCompleter helpCompleter = new HelpCompleter("");
+
+ @Test
+ public void testScanShouldStripArgs() {
+ String line = "log set [] OFF|ERROR|WARN|INFO|DEBUG|TRACE|ALL";
+ String processed = helpCompleter.scan(line);
+ assertEquals("log set", processed);
+ }
+
+ @Test
+ public void testScanShouldStripWhitespaceSeparatedHyphen() {
+ String line = "set max diskspace -";
+ String processed = helpCompleter.scan(line);
+ assertEquals("set max diskspace", processed);
+ }
+
+ @Test
+ public void testScanShouldAcceptHyphenContainingCommand() {
+ String line = "chimera-maintenance ha show participants";
+ String processed = helpCompleter.scan(line);
+ assertEquals("chimera-maintenance ha show participants", processed);
+ }
+}