Repository navigation
CAMEL-27055: camel-jbang - camel get and camel cmd create only the sub-command that runs - #30207
Conversation
…t all commands and plugins cmd was one of the commands that consume plugins, so camel cmd created all the commands of the CLI and loaded every plugin (the TUI, Jackson, Citrus, Kubernetes). No plugin adds to cmd, and its subcommands do not use plugins, so it now creates only itself, as the other commands do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…b-command that runs The CLI created every sub-command of a group (camel get and camel cmd have about 40 each), and aesh read the annotations of each of them, while the command line runs one. - CommandTree gives aesh only the sub-command that the command line names, at every level; with no arguments, an option such as --help, or a name that is not a sub-command (for the suggestions of aesh), all of them as before. - CommandTree.lazy(factory): a tree whose command is created when first needed. The sub-commands of the groups of the CLI are added this way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
LGTM. Clean implementation of lazy command instantiation with well-structured test coverage.
The key design choices all check out:
getName()on a lazy tree returns the explicit name set byaddSubcommandwithout touching the factory — confirmed bytheCommandOfALazyTreetestWeakHashMapsemantics are preserved: the lazy command object is kept alive bythis.command, so no premature GCcomplete()correctly passesnullto always register all subcommands for tab completion- The
onlypath incontainer(builder, args)is exactly right: an unrecognized first arg falls through to the full list (with aesh suggestions), socamel get routstill says "Did you mean: route?"
One low-severity observation for awareness:
getCommand() lazy init is not thread-safe — the command field is non-volatile, so two concurrent callers could both see null and call factory.get() twice, with the second overwriting TREES. In the CLI's single-threaded dispatch this is a non-issue today, but worth noting if CommandTree is ever used in a multi-threaded context. A volatile annotation on the field would eliminate the risk at zero cost.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
CAMEL-27048 (#30201), the base of this branch, is on main now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
oscerd
left a comment
There was a problem hiding this comment.
Consistent next step after #30201, and the mechanism is the right one.
camel get and camel cmd each carry about 40 sub-commands, and creating the group created every one of them, loading its class, even though only the one named on the command line runs. Wrapping each in CommandTree.lazy(() -> new ...) defers that construction until the sub-command is actually selected, so running camel get route or camel cmd reset-stats no longer pays to load the other 39. This is the same deferral idea as the embedded-plugin change, applied one level down to the sub-command tree.
The lambda use here is the correct trade in this context, and it is worth noting it does not conflict with the "no lambdas" note in the catalog-header change: there the one-time metafactory cost rivalled the saving on a hot, already-lean path, whereas here each lazy supplier avoids loading a whole sub-command class and its dependencies, so the deferral clearly wins. Dispatch still resolves by name and instantiates the selected sub-command on demand, so nothing a command needs is lost, only postponed.
Noted that this is stacked on #30201, with its base on that branch and only this change in the diff, so it should retarget to main once #30201 lands. Reviewed on that basis. Good.
Claude Code on behalf of oscerd
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 5 of 726 tested, 8 compile-only — current: 5 all testedMaveniverse Scalpel detected 5 affected modules (current approach: 5). Skip-tests mode would test 5 modules (1 direct + 5 downstream), skip tests for 8 (generated code, meta-modules) Modules Scalpel would test (5)
Modules with tests skipped (8)
💡 Manual integration tests recommended:
All tested modules (14 modules, 1m 40s total)Total reactor time: 1m 40s
Top 20 slowest modules:
|
CAMEL-27055
Follows #30201 (CAMEL-27048,
camel cmdcreates only its own command), which is merged; this PR now targetsmain.camel get route,camel cmd reset-statsand the other sub-commands of a command with many (get and cmd have about 40 each) cost 25-30 ms more thancamel ps. The CLI created every sub-command of the group (loading their classes: 14 ms with the CDS archive of camel.sh, 36 ms without), and aesh read the annotations of each of them, while the command line runs one.Changes
CommandTreegives aesh only the sub-command that the command line names (camel get route: onlyroute), at every level. With no arguments, an option such as--help, or a name that is not a sub-command (aesh then suggests the sub-commands:camel get routstill says "Did you mean: route?"), it gives all of them, as before. Completion andparser()always get all of them.CommandTree.lazy(factory): a tree whose command is created when it is first needed (when it runs, when aesh lists it, or ongetCommand()), and is registered forCommandTree.ofthen.CamelJBangMainadds the 117 sub-commands of its groups (get, cmd, catalog, config, infra, ...) this way; the top-level commands were already created only when named (CAMEL-26428).Measured
JDK 25, macOS (Apple M4 Pro), through
camel.sh(with its CDS archive), no integration running, median of 15 runs. CPU time (user + system) of the process, with the wall time in brackets; the machine was busy, CPU time is the steadier number.camel pscamel get routecamel get healthcamel cmd reset-statscamel cmd route-structureTests
Ran locally (before the retarget to
main):CommandTreeLazyTest(new): a sub-command is created when it runs and its sibling is not;--helpand a name that is not a sub-command create all (with the suggestion); a lazy tree has its name without creating the command, and registers it when created.IntegrationLauncherCommandLineTest.anIntegrationInDevModeThatWatchesItsOwnFilesfailed once under the full suite and passed on the retry; it does not use the command tree, and passed 3 of 3 runs on its own).get --help,cmd --help,catalog --help,get route-controller --help,get rout(exit 2, suggestion),cmd reset-stats,cmd route-structure,get route --json(counters left out) andconfig listgive the same output and exit code.Related: #30199 (CAMEL-27045), #30201 (CAMEL-27048), #30203 (CAMEL-27050).
Claude Code on behalf of davsclaus
🤖 Generated with Claude Code