From 6c392addc1db5b8dc69f61ccd07886a62463c896 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 11 Mar 2022 17:22:52 +0100 Subject: [PATCH] Add hidden generate-completion command This command can be used to generate zsh/bash autocompletion. See https://picocli.info/autocomplete.html --- .../src/main/java/sop/cli/picocli/SopCLI.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sop-java-picocli/src/main/java/sop/cli/picocli/SopCLI.java b/sop-java-picocli/src/main/java/sop/cli/picocli/SopCLI.java index bc0ae3d..1d79f0a 100644 --- a/sop-java-picocli/src/main/java/sop/cli/picocli/SopCLI.java +++ b/sop-java-picocli/src/main/java/sop/cli/picocli/SopCLI.java @@ -4,6 +4,7 @@ package sop.cli.picocli; +import picocli.AutoComplete; import picocli.CommandLine; import sop.SOP; import sop.cli.picocli.commands.ArmorCmd; @@ -30,7 +31,8 @@ import sop.cli.picocli.commands.VersionCmd; GenerateKeyCmd.class, SignCmd.class, VerifyCmd.class, - VersionCmd.class + VersionCmd.class, + AutoComplete.GenerateCompletion.class } ) public class SopCLI { @@ -47,12 +49,17 @@ public class SopCLI { } public static int execute(String[] args) { - return new CommandLine(SopCLI.class) - .setCommandName(EXECUTABLE_NAME) + CommandLine cmd = new CommandLine(SopCLI.class); + // Hide generate-completion command + CommandLine gen = cmd.getSubcommands().get("generate-completion"); + gen.getCommandSpec().usageMessage().hidden(true); + + cmd.setCommandName(EXECUTABLE_NAME) .setExecutionExceptionHandler(new SOPExecutionExceptionHandler()) .setExitCodeExceptionMapper(new SOPExceptionExitCodeMapper()) - .setCaseInsensitiveEnumValuesAllowed(true) - .execute(args); + .setCaseInsensitiveEnumValuesAllowed(true); + + return cmd.execute(args); } public static SOP getSop() {