Skip to content

Commit

Permalink
Merge pull request #579 from jonesbusy/feature/setup-completionCandid…
Browse files Browse the repository at this point in the history
…ates

Auto-completion
  • Loading branch information
jonesbusy authored Jan 6, 2025
2 parents 5c071d5 + dfebda9 commit ab46a2a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ From there you need to save both ID of installation (found on URL)
- `build-metadata`: Collect metadata for the given plugin and have them on the local cache
- `recipes`: List available recipes

# Auto completion

```shell
source <(plugin-modernizer generate-completion)
```

## Global option

- `--debug`: (optional) Enables debug mode. Defaults to false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.jenkins.tools.pluginmodernizer.cli.command.ValidateCommand;
import io.jenkins.tools.pluginmodernizer.cli.command.VersionCommand;
import org.slf4j.bridge.SLF4JBridgeHandler;
import picocli.AutoComplete;
import picocli.CommandLine;
import picocli.CommandLine.Command;

Expand All @@ -16,6 +17,7 @@
description = "Plugin Modernizer. A tool to modernize Jenkins plugins",
synopsisSubcommandLabel = "COMMAND",
subcommands = {
AutoComplete.GenerateCompletion.class,
ValidateCommand.class,
ListRecipesCommand.class,
BuildMetadataCommand.class,
Expand All @@ -39,6 +41,9 @@ public class Main {
* @param args Command line arguments
*/
public static void main(final String[] args) {
System.exit(new CommandLine(new Main()).execute(args));
CommandLine cmd = new CommandLine(new Main());
CommandLine gen = cmd.getSubcommands().get("generate-completion");
gen.getCommandSpec().usageMessage().hidden(true);
System.exit(cmd.execute(args));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class DryRunCommand implements ICommand {
names = {"-r", "--recipe"},
required = true,
description = "Recipe to be applied.",
completionCandidates = RecipeConverter.class,
converter = RecipeConverter.class)
private Recipe recipe;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class RunCommand implements ICommand {
names = {"-r", "--recipe"},
required = true,
description = "Recipe to be applied.",
completionCandidates = RecipeConverter.class,
converter = RecipeConverter.class)
private Recipe recipe;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import io.jenkins.tools.pluginmodernizer.core.config.Settings;
import io.jenkins.tools.pluginmodernizer.core.model.Recipe;
import java.util.Iterator;
import picocli.CommandLine;

/**
* Custom converter for Recipe interface.
*/
public final class RecipeConverter implements CommandLine.ITypeConverter<Recipe> {
public final class RecipeConverter implements CommandLine.ITypeConverter<Recipe>, Iterable<String> {
@Override
public Recipe convert(String value) {
return Settings.AVAILABLE_RECIPES.stream()
Expand All @@ -19,4 +20,11 @@ public Recipe convert(String value) {
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Invalid recipe name: " + value));
}

@Override
public Iterator<String> iterator() {
return Settings.AVAILABLE_RECIPES.stream()
.map(r -> r.getName().replace(Settings.RECIPE_FQDN_PREFIX + ".", ""))
.iterator();
}
}

0 comments on commit ab46a2a

Please sign in to comment.