feat(cli): keep Windows paths in editor values and say what to do for a pinned image

A backslash in VISUAL or EDITOR is an escape only before a space or a quote, so Windows paths come through intact. The old-server hint explains that restart keeps a pinned tag and how to change it.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura committed 2026-10-10 23:40:07 -05:00
1 parent 3570d5fa04
commit e661cc29bf
3 files changed
+36 -11

No files matched your search

@@ -26,10 +26,15 @@ public final class ServerCompatibility {
return Optional.empty();
}
// restart, not stop and start: it brings the instance back with the port, data directory
// and services it has now.
// and services it has now. It also keeps the image reference, so an instance pinned to an
// old tag needs that changed first; the hint says where.
String prefix = product.commandPrefix();
return Optional.of(product.displayName() + " server " + serverVersion + " is older than "
+ ImageVersionCheck.MIN_VERSION + ", the oldest version this CLI supports; some commands may not work."
+ "\nPull a newer image ('docker pull " + product.defaultImageRef() + "'), then run '"
+ product.commandPrefix() + " restart" + instanceSelector + "'.");
+ prefix + " restart" + instanceSelector + "'."
+ "\nIf the instance pins an older tag, restart keeps it: change 'image' in its profile first, or run '"
+ prefix + " stop --remove" + instanceSelector + "' and start it again with its usual flags plus"
+ " '--image " + product.defaultImageRef() + "'.");
}
}
@@ -255,9 +255,11 @@ public class ConfigProfileCommand implements Callable<Integer> {
/**
* {@code line} split into words the way a shell would for a simple command: whitespace
* separates, single and double quotes group (a path with spaces), and a backslash outside
* single quotes takes the next character literally. Nothing is expanded; the words go
* straight to the process, never through a shell.
* separates, and single and double quotes group (a path with spaces). A backslash is an
* escape only in front of a space or a quote; anywhere else it is an ordinary character, so
* a Windows path ({@code C:\Windows\System32\notepad.exe}, {@code \\server\share\edit})
* comes through intact. Nothing is expanded; the words go straight to the process, never
* through a shell.
*/
static List<String> words(String line) {
List<String> words = new ArrayList<>();
@@ -269,8 +271,7 @@ public class ConfigProfileCommand implements Callable<Integer> {
if (quote != 0) {
if (c == quote) {
quote = 0;
} else if (c == '\\' && quote == '"' && i + 1 < line.length()
&& (line.charAt(i + 1) == '"' || line.charAt(i + 1) == '\\')) {
} else if (c == '\\' && quote == '"' && i + 1 < line.length() && line.charAt(i + 1) == '"') {
word.append(line.charAt(++i));
} else {
word.append(c);
@@ -278,7 +279,7 @@ public class ConfigProfileCommand implements Callable<Integer> {
} else if (c == '\'' || c == '"') {
quote = c;
inWord = true;
} else if (c == '\\' && i + 1 < line.length()) {
} else if (c == '\\' && i + 1 < line.length() && escapable(line.charAt(i + 1))) {
word.append(line.charAt(++i));
inWord = true;
} else if (Character.isWhitespace(c)) {
@@ -296,6 +297,10 @@ public class ConfigProfileCommand implements Callable<Integer> {
return List.copyOf(words);
}
private static boolean escapable(char next) {
return Character.isWhitespace(next) || next == '"' || next == '\'';
}
private int createProfile(Printer printer, ProfileStore store) {
if (name == null) { printer.error(nameRequired()); return 1; }
try {
@@ -187,6 +187,10 @@ class ErgonomicsTest {
"code --wait | code;--wait",
"nano --rcfile=\"my rc\" | nano;--rcfile=my rc",
"echo \"a \\\"quoted\\\" word\" | echo;a \"quoted\" word",
"C:\\Windows\\System32\\notepad.exe | C:\\Windows\\System32\\notepad.exe",
"\"C:\\Program Files\\Microsoft VS Code\\bin\\code.cmd\" --wait | C:\\Program Files\\Microsoft VS Code\\bin\\code.cmd;--wait",
"\\\\tools\\share\\edit.exe -n | \\\\tools\\share\\edit.exe;-n",
"'C:\\my tools\\edit.exe' | C:\\my tools\\edit.exe",
"ed '' | ed;"})
void anEditorValueIsSplitLikeAShellWould(String value, String expected) {
assertEquals(List.of(expected.split(";", -1)), ConfigProfileCommand.editorCommand(value, null));
@@ -272,7 +276,7 @@ class ErgonomicsTest {
assertTrue(warning.contains("server " + version + " is older than 1.5.0"), warning);
assertTrue(warning.contains("docker pull floci/floci:latest"), warning);
assertTrue(warning.endsWith("then run 'floci restart'."), warning);
assertTrue(warning.contains("then run 'floci restart'."), warning);
}
@ParameterizedTest
@@ -295,8 +299,19 @@ class ErgonomicsTest {
void theHintSelectsTheSameInstance() {
String warning = ServerCompatibility.warning(ProductProfile.AWS, "1.4.0", " --profile dev").orElseThrow();
assertTrue(warning.endsWith("then run 'floci restart --profile dev'."), warning);
assertFalse(warning.contains("stop --remove"), warning);
assertTrue(warning.contains("then run 'floci restart --profile dev'."), warning);
// The way out for a pinned tag acts on the same instance too.
assertTrue(warning.contains("floci stop --remove --profile dev"), warning);
}
/** restart keeps the image reference, so the hint says what to do when that reference is the old tag. */
@Test
void theHintCoversAnInstancePinnedToAnOldTag() {
String warning = ServerCompatibility.warning(ProductProfile.AWS, "1.4.0", " --container dev").orElseThrow();
assertTrue(warning.contains("If the instance pins an older tag, restart keeps it"), warning);
assertTrue(warning.contains("change 'image' in its profile"), warning);
assertTrue(warning.contains("'--image floci/floci:latest'"), warning);
}
@Test