luigidemasi commented on code in PR #185:
URL: https://github.com/apache/camel-kit/pull/185#discussion_r4607291584
##########
.github/workflows/build.yml:
##########
@@ -69,10 +75,34 @@ jobs:
**/target/failsafe-reports/*.xml
retention-days: 7
+ cli-compatibility:
+ name: CLI compatibility (${{ matrix.os }}, Java ${{ matrix.java }})
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [macos-latest, windows-latest]
+ java: [17, 21, 25]
+ steps:
+ - uses: actions/[email protected]
+ - uses: actions/[email protected]
+ with:
+ java-version: ${{ matrix.java }}
+ distribution: temurin
+ cache: maven
+ - name: Verify token binding, host discovery, redirected output and
generated command prefixes
+ shell: bash
+ run: |
+ if [ "${{ matrix.java }}" = "17" ]; then
+ ./mvnw -B -pl kit/camel-kit-main -am test
-Dtest=AeshCliCompatibilityTest,ArgumentFilesTest,CamelKitMainShipTest
-Dsurefire.failIfNoSpecifiedTests=false
+ else
+ ./mvnw -B -pl kit/camel-jbang-plugin-kit -am test
"-Dtest=AeshCliCompatibilityTest,ArgumentFilesTest,CamelKitMainShipTest,CamelKitPluginTest,CamelKitCommandParityTest#nativeInitAndRegenerationDetectThePrefixInSeparateProcesses+pluginRegistersStandaloneCommandSurface+bob2InitAndRegenerationExposeTheSamePublicSkills+pluginForwardsWithCitrusMcpOption,HostedCliCompatibilityTest"
-Dsurefire.failIfNoSpecifiedTests=false
Review Comment:
Fixed in
[2959eabf](https://github.com/apache/camel-kit/commit/2959eabfe8227ab90f72ea91cdea8fabded3fd1d).
The compatibility tests use `@Tag("cli-compat")`; CI installs dependencies
first, then runs the core and plugin modules with `-Dgroups=cli-compat
-DfailIfNoTests=true`. Method-name selectors, the Java 17 branch and
`failIfNoSpecifiedTests=false` are removed from this lane.
Verified 19 core plus 17 plugin cases on Java 21 and 25. Negative controls
using a nonexistent tag fail in each module, so an empty selected suite cannot
report success. Reports are uploaded even on failure.
_AI-generated by OpenAI Codex on behalf of @luigidemasi._
##########
kit/camel-kit-core/src/main/java/org/apache/camel/kit/CommandRunner.java:
##########
@@ -0,0 +1,200 @@
+package org.apache.camel.kit;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.camel.kit.command.CliCommand;
+
+import org.aesh.command.AeshCommandRuntimeBuilder;
+import org.aesh.command.Command;
+import org.aesh.command.CommandRuntime;
+import org.aesh.command.HelpFeature;
+import org.aesh.command.container.CommandContainer;
+import org.aesh.command.impl.container.AeshCommandContainer;
+import org.aesh.command.impl.container.AeshCommandContainerBuilder;
+import org.aesh.command.impl.parser.CommandLineParser;
+import org.aesh.command.impl.registry.AeshCommandRegistryBuilder;
+import org.aesh.command.impl.shell.StdoutShell;
+import org.aesh.command.invocation.CommandInvocation;
+import org.aesh.command.parser.CommandLineParserException;
+import org.aesh.command.parser.RequiredOptionException;
+import org.aesh.command.validator.CommandValidatorException;
+import org.aesh.command.validator.OptionValidatorException;
+
+/** One-shot argv execution. The runtime owns no interactive terminal. */
+public final class CommandRunner {
+ private final Command<CommandInvocation> command;
+ private final Map<String, CommandRunner> children = new LinkedHashMap<>();
+ private PrintWriter out = new PrintWriter(System.out, true,
java.nio.charset.Charset.defaultCharset());
+ private PrintWriter err = new PrintWriter(System.err, true,
java.nio.charset.Charset.defaultCharset());
+ private boolean argumentFiles;
+ private CommandLineParser<CommandInvocation> parser;
+ private CommandContainer<CommandInvocation> container;
+
+ public CommandRunner(Command<CommandInvocation> command) {
+ this.command = command;
+ }
+
+ public CommandRunner addSubcommand(String name, Command<CommandInvocation>
child) {
+ return addSubcommand(name, new CommandRunner(child));
+ }
+
+ public CommandRunner addSubcommand(String name, CommandRunner child) {
+ children.put(name, child);
+ container = null;
+ parser = null;
+ return this;
+ }
+
+ public CommandRunner argumentFiles(boolean enabled) {
+ argumentFiles = enabled;
+ return this;
+ }
+
+ public CommandRunner setOut(PrintWriter out) {
+ this.out = out;
+ return this;
+ }
+
+ public CommandRunner setErr(PrintWriter err) {
+ this.err = err;
+ return this;
+ }
+
+ public CommandLineParser<CommandInvocation> parser() {
+ if (parser == null) {
+ container();
+ }
+ return parser;
+ }
+
+ private CommandContainer<CommandInvocation> container() {
+ if (container != null) {
+ configure(parser, out, err);
+ return container;
+ }
+ try {
+ var builder = new AeshCommandContainerBuilder<CommandInvocation>();
+
builder.setHelpDefaults(EnumSet.of(HelpFeature.FAIL_ON_DUPLICATE_OPTIONS));
+ container = builder.create(command);
+ for (var entry : children.entrySet()) {
+ var child = entry.getValue().container();
+
child.getParser().getProcessedCommand().setName(entry.getKey());
+ ((AeshCommandContainer<CommandInvocation>)
container).addChild(child);
+ }
+ parser = container.getParser();
+ parser.updateAnsiMode(false);
+ configure(parser, out, err);
+ return container;
+ } catch (CommandLineParserException e) {
+ throw new IllegalStateException("Invalid command definition", e);
+ }
+ }
+
+ private static void configure(
+ CommandLineParser<CommandInvocation> parser,
+ PrintWriter out, PrintWriter err) {
+ if (parser.getCommand() instanceof CliCommand cli) {
+ cli.configureOutput(out, err);
+ }
+ for (var child : parser.getAllChildParsers()) {
+ configure(child, out, err);
+ }
+ }
+
+ private CommandRuntime<CommandInvocation> runtime() {
+ var registry =
AeshCommandRegistryBuilder.<CommandInvocation>builder().command(container()).create();
+ return AeshCommandRuntimeBuilder.<CommandInvocation>builder()
+
.commandRegistry(registry).argumentFiles(false).ansiColors(false)
+ .shell(new StdoutShell() {
+ @Override
+ public void write(String value, boolean paging) {
+ out.print(value);
+ out.flush();
+ }
+
+ @Override
+ public void writeln(String value, boolean paging) {
+ out.println(value);
+ out.flush();
+ }
+ }).build();
+ }
+
+ public void parse(String... args) throws Exception {
+ var runtime = runtime();
+ try {
+ for (var execution :
runtime.buildExecutor(parser.getProcessedCommand().name(), expand(args))
+ .getExecutions()) {
+ execution.populateCommand();
+ }
+ } finally {
+ runtime.close();
+ }
+ }
+
+ public int execute(String... args) {
+ var runtime = runtime();
+ try {
+ var executions =
runtime.buildExecutor(parser.getProcessedCommand().name(),
expand(args)).getExecutions();
+ var execution = executions.get(0);
+ try {
+ execution.populateCommand();
+ } catch (CommandLineParserException e) {
+ if (!rootInformationRequested() ||
!onlyInformationalErrors(parser)) {
+ throw e;
+ }
+ }
+ if (rootInformationRequested()) {
+ if (optionGiven("help")) {
+ out.print(parser.printHelp());
+ } else {
+ for (String version : new VersionProvider().getVersion()) {
+ out.println(version);
+ }
+ }
+ return 0;
+ }
+ return execution.execute().getResultValue();
+ } catch (IOException | CommandLineParserException |
OptionValidatorException | CommandValidatorException e) {
+ err.println(e.getMessage());
+ return 2;
+ } catch (Exception e) {
+ e.printStackTrace(err);
+ return 1;
+ } finally {
+ runtime.close();
+ out.flush();
+ err.flush();
+ }
+ }
+
+ private String[] expand(String[] args) throws IOException {
+ return argumentFiles ? ArgumentFiles.expand(args) : args;
+ }
+
+ private boolean rootInformationRequested() {
+ return command instanceof CamelKitMain && (optionGiven("help") ||
optionGiven("version"));
+ }
+
+ private boolean optionGiven(String name) {
+ return
!parser.getProcessedCommand().findLongOptionNoActivatorCheck(name).getValues().isEmpty();
+ }
+
+ // Root information flags excuse unknown tokens and omitted required
arguments, but never malformed options.
+ private static boolean onlyInformationalErrors(CommandLineParser<?>
parser) {
+ for (var error : parser.getProcessedCommand().parserExceptions()) {
+ if (!(error instanceof RequiredOptionException)
+ && !(error.getMessage().startsWith("The option ") &&
error.getMessage().contains(" is unknown."))
+ && !error.getMessage().startsWith("Unknown argument ")
+ && !error.getMessage().startsWith("Unexpected argument "))
{
+ return false;
+ }
+ }
+ return parser.getAllChildParsers().stream().filter(child ->
child.parsedCommand() != null)
+ .allMatch(CommandRunner::onlyInformationalErrors);
Review Comment:
Fixed in
[2959eabf](https://github.com/apache/camel-kit/commit/2959eabfe8227ab90f72ea91cdea8fabded3fd1d).
`onlyInformationalErrors` no longer examines English messages. Kit's strict
option parser throws a typed `MalformedOptionException`; informational handling
permits `RequiredOptionException` and the exact generic Aesh
`OptionParserException` only when all options use Kit's parser.
Regression coverage keeps `--version --invalid` at exit 0 while missing
values, duplicate options and malformed booleans/conversions remain exit 2 even
with root help/version. A mutation that replaced the malformed subtype with the
generic exception was caught by the regression test.
_AI-generated by OpenAI Codex on behalf of @luigidemasi._
##########
kit/camel-jbang-plugin-kit/src/main/java/org/apache/camel/kit/jbang/KitInitCommand.java:
##########
@@ -1,114 +1,20 @@
package org.apache.camel.kit.jbang;
-import java.nio.file.Path;
-import java.util.List;
-
-import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.kit.CamelKitMain;
import org.apache.camel.kit.command.InitCommand;
-import picocli.CommandLine.Command;
-import picocli.CommandLine.Option;
-import picocli.CommandLine.Parameters;
-
-/**
- * Adapter command for `camel kit init` - delegates to camel-kit-core
InitCommand
- */
-@Command(name = "init", description = "Initialize a new Camel-Kit project")
-public class KitInitCommand extends CamelCommand {
-
- @Parameters(index = "0", description = "Project name", arity = "0..1")
- String projectName;
-
- @Option(names = {"-a", "--ai"},
- description = "AI agent: bob2 (IBM Bob 2, default), antigravity, "
- + "claude, codex, copilot, pi, qwen, opencode",
- defaultValue = "bob2")
- String ai;
-
- @Option(names = {"--here"}, description = "Initialize in current
directory")
- boolean here;
-
- @Option(names = {"--citrus-version"},
- description = "Citrus version for test schemas",
- defaultValue = "default")
- String citrusVersion;
-
- @Option(names = {"--no-fetch"}, description = "Skip external catalog
fetching")
- boolean noFetch;
-
- @Option(names = {"--force"},
- description = "Reinitialize a project that already has
.camel-kit/. Files you changed are preserved")
- boolean force;
-
- @Option(names = {"--dry-run"},
- description = "Show what init would do to files the project may
already own, without writing anything")
- boolean dryRun;
-
- @Option(names = {"--replace"}, paramLabel = "<path>",
- description = "Replace this existing shared file (for example
AGENTS.md or mvnw) instead of "
- + "preserving it (repeatable)")
- List<String> replace;
-
- @Option(names = {"--silent"}, description = "Suppress all output (no
banner, no progress, no summary)")
- boolean silent;
-
- @Option(names = {"-c", "--config"},
- description = "Path to config properties file (default:
~/.camel-kit/config.properties)")
- Path configFile;
-
- @Option(names = {"-p", "--property"}, arity = "1..*",
- description = "Override config property: -p key=value
(repeatable)")
- List<String> properties;
-
- @Option(names = {"--with-citrus-mcp"},
- description = "Include the Citrus MCP server in agent
configuration (default: off)")
- boolean withCitrusMcp;
-
- @Option(names = {"--source-platform"},
- description = "Source platform for migration graph analysis:
mulesoft, camel, biztalk, auto (default: auto)")
- String sourcePlatform;
-
- @Option(names = {"--replace-wrapper"},
- description = "Replace Maven wrapper even if it exists (default:
preserve existing wrapper)")
- boolean replaceWrapper;
-
- @Option(names = {"--record-baseline"},
- description = "Run existing project tests during init to record
baseline (executes project build code; default: off)")
- boolean recordBaseline;
-
- private final CamelKitMain camelKitMain;
+import org.aesh.command.CommandDefinition;
+/** Uses the core option binding and initialization behavior inside the Camel
host. */
+@CommandDefinition(name = "init", description = "Initialize a new Camel-Kit
project", generateHelp = true)
+public class KitInitCommand extends InitCommand {
public KitInitCommand(CamelJBangMain main) {
Review Comment:
Fixed in
[2959eabf](https://github.com/apache/camel-kit/commit/2959eabfe8227ab90f72ea91cdea8fabded3fd1d):
removed `KitInitCommand` entirely and [registered the shared `InitCommand`
directly](https://github.com/apache/camel-kit/blob/d3e062367cb235695ed09304472858e804c44598/kit/camel-jbang-plugin-kit/src/main/java/org/apache/camel/kit/jbang/CamelKitPlugin.java#L24).
This removes both unused constructor parameters and redundant
terminal-disabling calls. Plugin initialization/regeneration and generated
command-prefix checks pass.
_AI-generated by OpenAI Codex on behalf of @luigidemasi._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]