luigidemasi commented on code in PR #27646:
URL: https://github.com/apache/camel/pull/27646#discussion_r4236688570


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java:
##########
@@ -123,6 +123,7 @@ public void execute(String... args) {
                         .addSubcommand("route-dump", new CommandLine(new 
CamelRouteDumpAction(this)))
                         .addSubcommand("route-structure", new CommandLine(new 
CamelRouteStructureAction(this)))
                         .addSubcommand("route-topology", new CommandLine(new 
CamelRouteTopologyAction(this)))
+                        .addSubcommand("semantic-evaluate", new 
CommandLine(new SemanticEvaluate(this)))

Review Comment:
   Addressed in 
[cb9e3be25ada](https://github.com/apache/camel/commit/cb9e3be25adaa3caeb47fc0928aa01d4364cfdfe)
 using [your separate semantic-group 
suggestion](https://github.com/apache/camel/pull/27646#issuecomment-6094331686):
 `camel semantic` defaults to `camel semantic get`, and evaluation is `camel 
semantic eval`. This keeps inspection and evaluation together and removes the 
compound command name. The help, generated command metadata and documentation 
use this layout, and tests exercise all three forms through the actual root 
command.
   
   _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/CamelSemantic.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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 org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+import picocli.CommandLine;
+
[email protected](name = "semantic", description = "List semantic 
definitions and expert contracts",
+                     sortOptions = false, showDefaultValues = true)
+public class CamelSemantic extends SemanticActionCommand {
+
+    @CommandLine.Option(names = "--expert", description = "Show the operations 
and parameter contract of this expert")
+    String expert;
+
+    public CamelSemantic(CamelJBangMain main) {
+        super(main);
+    }
+
+    @Override
+    protected JsonObject request() {
+        if (expert != null && expert.isBlank()) {
+            throw new IllegalArgumentException("--expert must not be blank");
+        }
+        JsonObject request = new JsonObject();
+        request.put("action", "semantic-metadata");
+        if (expert == null) {
+            request.put("overview", true);
+        } else {
+            request.put("expert", expert);
+        }
+        return request;
+    }
+
+    @Override
+    protected int printResponse(JsonObject response) {
+        if (expert != null) {
+            JsonArray operations = response.getCollection("operations");
+            if (operations == null || operations.isEmpty()) {
+                return error(3, "No operations available for semantic expert: 
" + expert, null);
+            }
+        }
+        return super.printResponse(response);
+    }
+
+    @Override
+    protected void render(JsonObject response) {
+        if (expert != null) {
+            printer().println("Expert: " + expert);
+            renderOperations(response.getCollection("operations"));
+            return;
+        }
+        printer().println("Definitions:");
+        printer().println("NAME\tEXPERT\tOPERATION\tSTATE\tRESULT 
TYPE\tERROR");

Review Comment:
   Fixed in 
[cb9e3be25ada](https://github.com/apache/camel/commit/cb9e3be25adaa3caeb47fc0928aa01d4364cfdfe).
 Both the definitions and experts lists now use 
`AsciiTable.getTable(AsciiTable.NO_BORDERS, ...)` with `Column` definitions and 
left-aligned data. `--json` remains the machine-readable format. The listing 
regression verifies aligned columns, resolution errors and the absence of tab 
separators.
   
   _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/SemanticActionCommand.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
+import org.apache.camel.util.json.JsonObject;
+import picocli.CommandLine;
+
+public abstract class SemanticActionCommand extends ActionBaseCommand {
+
+    @CommandLine.Parameters(description = "Name or pid of a running Camel 
integration", arity = "0..1")
+    String name = "*";
+
+    @CommandLine.Option(names = "--json", description = "Output a single JSON 
document")
+    boolean json;
+
+    @CommandLine.Option(names = "--timeout", defaultValue = "60000",
+                        description = "Timeout in milliseconds waiting for the 
integration")
+    long timeout = 60000;
+
+    @CommandLine.Spec
+    CommandLine.Model.CommandSpec commandSpec;
+
+    protected SemanticActionCommand(CamelJBangMain main) {
+        super(main);
+    }
+
+    @Override
+    public Integer doCall() {
+        try {
+            if (timeout <= 0) {
+                return error(2, "--timeout must be greater than zero", null);
+            }
+            JsonObject request;
+            try {
+                request = request();
+            } catch (IllegalArgumentException e) {
+                return error(2, e.getMessage(), null);
+            }
+            List<Long> pids = 
findPids(name).stream().filter(this::isRunningIntegration).toList();
+            if (pids.isEmpty()) {
+                return error(3, "No running Camel integration matches: " + 
name, null);
+            }
+            if (pids.size() != 1) {
+                return error(3, "Multiple Camel integrations match " + name + 
": " + pids + ". Specify a pid.", null);
+            }
+            JsonObject response = execute(pids.get(0), request);
+            if (response == null) {

Review Comment:
   Fixed in 
[cb9e3be25ada](https://github.com/apache/camel/commit/cb9e3be25adaa3caeb47fc0928aa01d4364cfdfe).
 After selecting an integration, the CLI checks `context.version` and returns 
exit 3 with the detected version and the 4.23 requirement before publishing a 
request when the version is too old. Tests cover older releases, vendor 
suffixes, supported versions and unknown versions; an unavailable version still 
uses the normal request timeout, as documented.
   
   One historical detail: per-request IPC was added during 4.21 development. 
The 4.23 minimum here is for the semantic tooling, so the diagnostic describes 
that requirement.
   
   _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]

Reply via email to