diff --git a/src/main/java/picocli/AutoComplete.java b/src/main/java/picocli/AutoComplete.java index a43f8ba5c..72d34d86e 100644 --- a/src/main/java/picocli/AutoComplete.java +++ b/src/main/java/picocli/AutoComplete.java @@ -305,6 +305,17 @@ private static class CommandDescriptor { this.commandName = commandName; this.commandLine = commandLine; } + + @Override + public String toString() { + return "CommandDescriptor{" + + "functionName='" + functionName + '\'' + + ", parentFunctionName='" + parentFunctionName + '\'' + + ", parentWithoutTopLevelCommand='" + parentWithoutTopLevelCommand + '\'' + + ", commandName='" + commandName + '\'' + + ", commandLine=" + commandLine + + '}'; + } } private static final String SCRIPT_HEADER = "" + @@ -534,6 +545,24 @@ public static String bash(String scriptName, CommandLine commandLine) { return result.toString(); } + + public static String fish(String scriptName, CommandLine commandLine) { + if (scriptName == null) { throw new NullPointerException("scriptName"); } + if (commandLine == null) { throw new NullPointerException("commandLine"); } + List hierarchy = createHierarchy(scriptName, commandLine); + //print hierarchy + for (CommandDescriptor descriptor : hierarchy) { + System.out.println(descriptor.functionName + " " + descriptor.commandName); + } + + StringBuilder result = new StringBuilder(); + result.append("Hello from fish!").append("\n"); + for (CommandDescriptor commandDescriptor : hierarchy) { + result.append(commandDescriptor.toString()).append("\n"); + } + return result.toString(); + } + private static List createHierarchy(String scriptName, CommandLine commandLine) { List result = new ArrayList(); result.add(new CommandDescriptor("_picocli_" + scriptName, "", "", scriptName, commandLine)); diff --git a/src/test/java/picocli/AutoCompleteTest.java b/src/test/java/picocli/AutoCompleteTest.java index 49b37b78b..d62e16dc3 100644 --- a/src/test/java/picocli/AutoCompleteTest.java +++ b/src/test/java/picocli/AutoCompleteTest.java @@ -2117,4 +2117,20 @@ public void testIssue1388_AliasesCommand() throws FileNotFoundException { existingScript.delete(); } } + + @Test + public void testFish() { + String expected = String.format("hello from fish%n"); + + assertEquals( + expected, + AutoComplete.fish("myapp", new CommandLine(new Issue1352CommandWithResourceBundle())) + ); + + assertEquals( + expected, + AutoComplete.fish("myapp", new CommandLine(new Issue1352ParentCommand())) + ); + + } }