luigidemasi commented on code in PR #27646:
URL: https://github.com/apache/camel/pull/27646#discussion_r4236688927
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/exceptionhandler/MissingPluginParameterExceptionHandler.java:
##########
@@ -33,6 +34,9 @@ public class MissingPluginParameterExceptionHandler
implements IParameterExcepti
public int handleParseException(ParameterException ex, String[] args)
throws Exception {
CommandLine cmd = ex.getCommandLine();
PrintWriter err = cmd.getErr();
+ if (cmd.getCommand() instanceof SemanticActionCommand semantic) {
Review Comment:
Fixed in
[cb9e3be25ada](https://github.com/apache/camel/commit/cb9e3be25adaa3caeb47fc0928aa01d4364cfdfe).
The generic handler now depends on `UsageErrorHandler`, implemented by
`SemanticActionCommand`, rather than the semantic command class. Its return
type is `Integer`: an exit code means handled, while `null` preserves the
standard picocli diagnostics.
The semantic implementation handles only requests for JSON output. Text
errors retain suggestions, the synopsis and the help hint. Regression tests
cover both commands, JSON flags before and after an invalid option,
`--json=false`, and the `--` separator.
_AI-generated by OpenAI Codex on behalf of Luigi De Masi (@luigidemasi)._
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/SemanticEvaluate.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.action;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+import picocli.CommandLine;
+
[email protected](name = "semantic-evaluate", description = "Evaluate a
semantic definition or expert operation",
+ sortOptions = false, showDefaultValues = true)
+public class SemanticEvaluate extends SemanticActionCommand {
+
+ private static final ObjectReader JSON_VALUE = new
ObjectMapper().readerFor(Object.class)
+ .with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
+
+ @CommandLine.Option(names = "--evaluation", description = "Named semantic
definition to evaluate")
+ String evaluation;
+
+ @CommandLine.Option(names = "--body", description = "Sample message body
(text, file:path or json:value)")
+ String body;
+
+ @CommandLine.Option(names = "--header", description = "Sample header
(key=value; use json: for a typed value)")
+ List<String> headers;
+
+ @CommandLine.Option(names = "--variable",
+ description = "Sample exchange-local variable
(key=value; use json: for a typed value)")
+ List<String> variables;
+
+ @CommandLine.Option(names = "--expert", description = "Expert to call
directly")
+ String expert;
+
+ @CommandLine.Option(names = "--operation", description = "Expert operation
to call directly")
+ String operation;
+
+ @CommandLine.Option(names = "--input", description = "Direct expert input
(text, file:path or json:value)")
+ String input;
+
+ @CommandLine.Option(names = "--parameter", description = "Expert parameter
(key=value; use json: for a typed value)")
+ List<String> parameters;
+
+ @CommandLine.Option(names = "--evaluation-timeout", defaultValue = "50000",
+ description = "Provider evaluation timeout in
milliseconds (1-50000)")
+ long evaluationTimeout = 50000;
+
+ public SemanticEvaluate(CamelJBangMain main) {
+ super(main);
+ }
+
+ @Override
+ protected JsonObject request() {
+ if (evaluationTimeout < 1 || evaluationTimeout > 50000) {
+ throw new IllegalArgumentException("--evaluation-timeout must be
between 1 and 50000 milliseconds");
+ }
+ JsonObject request = new JsonObject();
+ request.put("action", "semantic-evaluate");
+ request.put("timeout", evaluationTimeout);
+ if (evaluation != null) {
+ requireText(evaluation, "--evaluation");
+ if (expert != null || operation != null || input != null ||
parameters != null) {
+ throw new IllegalArgumentException("Choose --evaluation or
--expert with --operation and --input");
+ }
+ request.put("evaluation", evaluation);
+ if (body != null) {
+ request.put("body", value(body, true));
+ }
+ if (headers != null) {
+ request.put("headers", values(headers, "--header"));
+ }
+ if (variables != null) {
+ JsonObject sampleVariables = values(variables, "--variable");
+ if (sampleVariables.keySet().stream().anyMatch(key ->
key.contains(":"))) {
+ throw new IllegalArgumentException(
+ "Sample variables must have exchange-local names
without a repository prefix");
+ }
+ request.put("variables", sampleVariables);
+ }
+ } else {
+ requireText(expert, "--expert");
Review Comment:
Fixed in
[cb9e3be25ada](https://github.com/apache/camel/commit/cb9e3be25adaa3caeb47fc0928aa01d4364cfdfe).
With no evaluation or direct-call selection, the diagnostic now presents both
choices: a named evaluation, or an expert with an operation and input. It still
returns exit 2 without creating an action file. The regression checks the full
diagnostic and verifies that no request is sent.
_AI-generated by OpenAI Codex on behalf of Luigi De Masi (@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]