Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.keycloak.quarkus.runtime.cli.command;

import picocli.CommandLine;

@CommandLine.Command(name = Help.NAME, header = Help.HEADER, description = "%n" + Help.HEADER,
subcommands = {HelpFeatures.class})
public class Help {
public static final String NAME = "help";
public static final String HEADER = "Get more help about specific components";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.keycloak.quarkus.runtime.cli.command;

import io.quarkus.dev.console.QuarkusConsole;
import org.keycloak.common.Profile;
import picocli.CommandLine;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@CommandLine.Command(name = HelpFeatures.NAME, header = HelpFeatures.HEADER, description = "%n" + HelpFeatures.HEADER)
public class HelpFeatures extends AbstractCommand {
public static final String NAME = "features";
public static final String HEADER = "Information about features";
private static final List<Profile.Feature.Type> IGNORED_TYPES = List.of(Profile.Feature.Type.DEFAULT, Profile.Feature.Type.DISABLED_BY_DEFAULT);

@Override
public String getName() {
return NAME;
}

@Override
protected void runCommand() {
var out = spec.commandLine().getOut();
var ansi = QuarkusConsole.hasColorSupport() ? CommandLine.Help.Ansi.ON : CommandLine.Help.Ansi.OFF;
var enabled = new ArrayList<Profile.Feature>();
var disabled = new ArrayList<Profile.Feature>();

for (var f : Profile.Feature.values()) {
if (Profile.isFeatureEnabled(f)) {
enabled.add(f);
} else {
disabled.add(f);
}
}

printSection(out, ansi, "Enabled features:", enabled, true);
out.println();
printSection(out, ansi, "Disabled features:", disabled, false);

System.exit(0);
}

private void printSection(PrintWriter out, CommandLine.Help.Ansi ansi, String title,
List<Profile.Feature> features, boolean toEnable) {
out.println(ansi.string("@|bold " + title + "|@"));
features.forEach(f -> {
String typeDisplay = "";
if (!IGNORED_TYPES.contains(f.getType())) {
typeDisplay = " (" + colorizeType(f.getType(), ansi) + ")";
}

String key = toEnable ? f.getVersionedKey() : f.getUnversionedKey();
String formattedKey = ansi.string("@|bold " + key + "|@");
out.printf(" %s%s%n", formattedKey, typeDisplay);
out.printf(" %s%n", f.getLabel());
});
}

private String colorizeType(Profile.Feature.Type type, CommandLine.Help.Ansi ansi) {
String label = type.getLabel();
String color = switch (type) {
case PREVIEW, PREVIEW_DISABLED_BY_DEFAULT -> "yellow";
case EXPERIMENTAL -> "magenta";
case DEPRECATED -> "red";
default -> "default";
};
return ansi.string("@|" + color + " " + label + "|@");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
ShowConfig.class,
Tools.class,
BootstrapAdmin.class,
UpdateCompatibility.class
UpdateCompatibility.class,
Help.class
})
public final class Main {

Expand Down
Loading