diff --git a/cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java b/cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java index ff919cf54..17c015a00 100644 --- a/cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java +++ b/cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/CLIProcessor.java @@ -7,10 +7,12 @@ import static org.fusesource.jansi.Ansi.ansi; +import gov.nist.secauto.metaschema.cli.processor.command.CommandExecutionException; import gov.nist.secauto.metaschema.cli.processor.command.CommandService; import gov.nist.secauto.metaschema.cli.processor.command.ExtraArgument; import gov.nist.secauto.metaschema.cli.processor.command.ICommand; import gov.nist.secauto.metaschema.cli.processor.command.ICommandExecutor; +import gov.nist.secauto.metaschema.core.util.CollectionUtil; import gov.nist.secauto.metaschema.core.util.IVersionInfo; import gov.nist.secauto.metaschema.core.util.ObjectUtils; @@ -35,11 +37,10 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; -import java.util.Deque; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.stream.Collectors; @@ -164,6 +165,13 @@ private ExitStatus parseCommand(String... args) { assert commandArgs != null; CallingContext callingContext = new CallingContext(commandArgs); + if (LOGGER.isDebugEnabled()) { + String commandChain = callingContext.getCalledCommands().stream() + .map(ICommand::getName) + .collect(Collectors.joining(" -> ")); + LOGGER.debug("Processing command chain: {}", commandChain); + } + ExitStatus status; // the first two arguments should be the and , where // is the object type @@ -177,10 +185,16 @@ private ExitStatus parseCommand(String... args) { return status; } + @NonNull protected final List getTopLevelCommands() { - List retval = Collections.unmodifiableList(commands); - assert retval != null; - return retval; + return CollectionUtil.unmodifiableList(commands); + } + + @NonNull + protected final Map getTopLevelCommandsByName() { + return ObjectUtils.notNull(getTopLevelCommands() + .stream() + .collect(Collectors.toUnmodifiableMap(ICommand::getName, Function.identity()))); } private static void handleNoColor() { @@ -200,7 +214,8 @@ public static void handleQuiet() { } protected void showVersion() { - @SuppressWarnings("resource") PrintStream out = AnsiConsole.out(); // NOPMD - not owner + @SuppressWarnings("resource") + PrintStream out = AnsiConsole.out(); // NOPMD - not owner getVersionInfos().values().stream().forEach(info -> { out.println(ansi() .bold().a(info.getName()).boldOff() @@ -230,63 +245,44 @@ public class CallingContext { @NonNull private final List