davsclaus opened a new pull request, #28797:
URL: https://github.com/apache/camel/pull/28797

   [CAMEL-26466](https://issues.apache.org/jira/browse/CAMEL-26466), a step 
before the port of the CLI from picocli to aesh 
([CAMEL-23810](https://issues.apache.org/jira/browse/CAMEL-23810)).
   
   **What:** `PrepareCamelJBangCommandsMojo` writes the metadata of the 
commands (`camel-jbang-commands-metadata.json`, which `camel ask` uses) and, 
through the doc goal, the pages under `jbang-commands/`. Before, it read the 
commands from the Java source, in three ways:
   - regular expressions over the `addSubcommand` chains of `CamelJBangMain` 
and of the plugins;
   - Roaster for the picocli annotations;
   - reflection for the classes of a library.
   
   Now it loads `CommandMetadata` from camel-jbang-core with the classes of the 
project. That class walks the command model the CLI runs, and gives the 
commands as plain maps and lists:
   - for core, `CommandMetadata.commands()`;
   - for a plugin, `CommandMetadata.pluginCommands(pluginClass)`, with the 
plugin class read from its generated 
`META-INF/services/.../camel-jbang-plugin-<name>` file.
   
   The mojo keeps doing what it did with the result: it leaves out hidden 
commands and options, fills in the completion candidates, cleans the 
placeholders out of descriptions, maps the types, sorts, and writes the JSON. 
Only `CommandMetadata` knows picocli. At the switch to aesh only that class 
changes, and the committed JSON and pages show every difference.
   
   Descriptions and default values come from the annotations as written (with 
their constants resolved by the compiler), not as picocli fills them in. 
Otherwise a variable such as `${camel-version}` would depend on the system 
properties of the JVM that builds the docs.
   
   **Regenerated metadata and pages.** I compared every field of the 8 metadata 
files with `main`. All commands and options are the same; what differs is only 
what reading the source got wrong:
   
   | What | Count (core + plugins) | Before → after |
   |---|---|---|
   | A constant as default value | 24 | `RuntimeType.SPRING_BOOT_VERSION` → 
`4.1.2`, `DEFAULT_MODEL` → `llama3.2` |
   | Quotes in a description | 43 | `--label my.company=hello` → `"--label 
my.company=hello"` |
   | `+` in a description | 2 | `0=Created Completed` → `0=Created+Completed` |
   | An array option | 52 | `String` / `string` → `String[]` / `array` |
   | A nested enum type | 5 | `commands.ToolSet` (wrong class) → 
`commands.Ask.ToolSet` |
   | Completion candidates from the wrong list | 1 | `cmd receive --output`: 
`(auto, true, false)` → `(text, json)` |
   | Completion candidates of a plugin option, in a core class | 10 | `Profile 
to export .` → `Profile to export (dev, test, prod).` |
   
   The edit, mcp, test (including the Citrus commands) and tui plugins have no 
change.
   
   **Tests:**
   - `CommandMetadataTest` (core):
     - against the real command tree: `completion` is added under another name 
than its `@Command` name, `--reload,--dev`, and `${camel-version}` stays as 
written;
     - with a test plugin: an alias, a hidden and deprecated sub-command, an 
inherited (`scope = INHERIT`) option, and the param label.
   - `PrepareCamelJBangCommandsMojoTest` (rewritten): it compiles a 
`CommandMetadata` that gives fixed commands into the classes of the project, 
and runs the mojo for core and for a plugin. It also covers hidden commands and 
options, the help hint in a description, the completion candidates, the array 
type, a module without commands, and an error.
   - The old tests covered pitfalls of reading the source (interfaces as 
mixins, static imports, a class of a library with the name of a core command), 
which no longer exist.
   - `CliParseGoldenTest` passes.
   
   _Claude Code on behalf of davsclaus (Claus Ibsen)_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_0128ThHB3iQdrvSRLVBGRrdP
   


-- 
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