Skip to content

CAMEL-27055: camel-jbang - camel get and camel cmd create only the sub-command that runs - #30207

Merged
davsclaus merged 3 commits into
mainfrom
CAMEL-27055-only-subcommand
Nov 16, 2026
Merged

davsclaus merged 3 commits into
mainfrom
CAMEL-27055-only-subcommand

Conversation

@davsclaus

@davsclaus davsclaus commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

CAMEL-27055

Follows #30201 (CAMEL-27048, camel cmd creates only its own command), which is merged; this PR now targets main.

camel get route, camel cmd reset-stats and the other sub-commands of a command with many (get and cmd have about 40 each) cost 25-30 ms more than camel 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

  • CommandTree gives aesh only the sub-command that the command line names (camel get route: only route), 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 rout still says "Did you mean: route?"), it gives all of them, as before. Completion and parser() 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 on getCommand()), and is registered for CommandTree.of then. CamelJBangMain adds 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.

command main #30201 this PR
camel ps 220 ms (134 ms) 218 ms (132 ms) 217 ms (133 ms)
camel get route 299 ms (163 ms) 289 ms (158 ms) 239 ms (140 ms)
camel get health 304 ms (166 ms) 300 ms (164 ms) 239 ms (141 ms)
camel cmd reset-stats 618 ms (257 ms) 296 ms (162 ms) 234 ms (138 ms)
camel cmd route-structure 631 ms (254 ms) 293 ms (160 ms) 236 ms (140 ms)

Tests

Ran locally (before the retarget to main):

  • CommandTreeLazyTest (new): a sub-command is created when it runs and its sibling is not; --help and 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.
  • camel-jbang-core: 3101 run, 0 failures (one flake: IntegrationLauncherCommandLineTest.anIntegrationInDevModeThatWatchesItsOwnFiles failed 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).
  • camel-launcher: 418 run, 0 failures, 47 skipped.
  • Distribution, against main with a running integration: 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) and config list give 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

davsclaus and others added 2 commits November 16, 2026 13:58
…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>
@davsclaus davsclaus added this to the 4.24.0 milestone Nov 16, 2026
@davsclaus davsclaus added dsl enhancement New feature or request labels Nov 16, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 by addSubcommand without touching the factory — confirmed by theCommandOfALazyTree test
  • WeakHashMap semantics are preserved: the lazy command object is kept alive by this.command, so no premature GC
  • complete() correctly passes null to always register all subcommands for tab completion
  • The only path in container(builder, args) is exactly right: an unrecognized first arg falls through to the full list (with aesh suggestions), so camel get rout still 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.

@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@davsclaus
davsclaus changed the base branch from CAMEL-27048-cmd-only to main November 16, 2026 16:01
@davsclaus davsclaus self-assigned this Nov 16, 2026
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 oscerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@davsclaus
davsclaus merged commit 6c2cb68 into main Nov 16, 2026
6 checks passed
@davsclaus
davsclaus deleted the CAMEL-27055-only-subcommand branch November 16, 2026 17:15
@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • dsl/camel-jbang/camel-jbang-core

🔬 Scalpel shadow comparison — Scalpel: 5 of 726 tested, 8 compile-only — current: 5 all tested

Maveniverse 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)
  • camel-jbang-mcp ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-mcp ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-tui ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-validate ← downstream of org.apache.camel:camel-jbang-core
  • camel-launcher-container ← downstream of org.apache.camel:camel-launcher
Modules with tests skipped (8)
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-launcher
  • coverage

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • dsl/camel-jbang/camel-jbang-core: 2 test(s) disabled on GitHub Actions

💡 Manual integration tests recommended:

You modified dsl/camel-jbang/camel-jbang-core. The related integration tests in dsl/camel-jbang/camel-jbang-it are excluded from CI. Consider running them manually:

mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
All tested modules (14 modules, 1m 40s total)

Total reactor time: 1m 40s

Module Duration Status
Camel :: JBang :: Plugin :: Validate 26.6s SUCCESS
Camel :: JBang :: Plugin :: Kubernetes 23.1s SUCCESS
Camel :: JBang :: Plugin :: Testing 17.4s SUCCESS
Camel :: JBang :: Plugin :: Generate 11.6s SUCCESS
Camel :: JBang :: Plugin :: MCP 6.3s SUCCESS
Camel :: Coverage 4.9s SUCCESS
Camel :: JBang :: Plugin :: Edit 4.5s SUCCESS
Camel :: Launcher :: Container 2.9s SUCCESS
Camel :: JBang :: Main 1.8s SUCCESS
Camel :: JBang :: Integration tests 1.1s SUCCESS
Camel :: JBang :: Core n/a
Camel :: JBang :: MCP n/a
Camel :: JBang :: Plugin :: TUI n/a
Camel :: Launcher n/a

Top 20 slowest modules:

  • Camel :: JBang :: Plugin :: Validate (26.6s)
  • Camel :: JBang :: Plugin :: Kubernetes (23.1s)
  • Camel :: JBang :: Plugin :: Testing (17.4s)
  • Camel :: JBang :: Plugin :: Generate (11.6s)
  • Camel :: JBang :: Plugin :: MCP (6.3s)
  • Camel :: Coverage (4.9s)
  • Camel :: JBang :: Plugin :: Edit (4.5s)
  • Camel :: Launcher :: Container (2.9s)
  • Camel :: JBang :: Main (1.8s)
  • Camel :: JBang :: Integration tests (1.1s)

⚙️ View full build and test results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dsl enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants