From e661cc29bf99cb97fc516266afbcaaba5d7c10bc Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Sat, 10 Oct 2026 23:40:07 -0500 Subject: [PATCH] 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 --- .../io/floci/cli/ServerCompatibility.java | 9 ++++++-- .../commands/config/ConfigProfileCommand.java | 17 +++++++++------ .../io/floci/cli/unit/ErgonomicsTest.java | 21 ++++++++++++++++--- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/floci/cli/ServerCompatibility.java b/src/main/java/io/floci/cli/ServerCompatibility.java index e951de3..e2e3d8d 100644 --- a/src/main/java/io/floci/cli/ServerCompatibility.java +++ b/src/main/java/io/floci/cli/ServerCompatibility.java @@ -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() + "'."); } } diff --git a/src/main/java/io/floci/cli/commands/config/ConfigProfileCommand.java b/src/main/java/io/floci/cli/commands/config/ConfigProfileCommand.java index 92a3ebd..2b3c9a3 100644 --- a/src/main/java/io/floci/cli/commands/config/ConfigProfileCommand.java +++ b/src/main/java/io/floci/cli/commands/config/ConfigProfileCommand.java @@ -255,9 +255,11 @@ public class ConfigProfileCommand implements Callable { /** * {@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 words(String line) { List words = new ArrayList<>(); @@ -269,8 +271,7 @@ public class ConfigProfileCommand implements Callable { 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 { } 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 { 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 { diff --git a/src/test/java/io/floci/cli/unit/ErgonomicsTest.java b/src/test/java/io/floci/cli/unit/ErgonomicsTest.java index b108832..02dd400 100644 --- a/src/test/java/io/floci/cli/unit/ErgonomicsTest.java +++ b/src/test/java/io/floci/cli/unit/ErgonomicsTest.java @@ -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