Bug
When a global option (e.g. --use-context, --config-file, --json) is placed before the subcommand name, the lazy-loading logic in src/cli.ts fails to detect the correct subcommand and registers only the empty stub instead of the full command tree.
Steps to reproduce
elastic --use-context serverless cloud elasticsearch-projects list-elasticsearch-projects
Expected: command runs normally
Actual:
Error: unknown command: elasticsearch-projects
Root cause
cli.ts uses process.argv[2] to identify the first subcommand:
const firstArg = process.argv[2]
if (firstArg === 'es') { ... }
if (firstArg === 'cloud') { ... }
When global flags precede the subcommand, argv[2] is the flag (e.g. --use-context) rather than the subcommand name (cloud), so the full command tree is never loaded.
Suggested fix
Scan for the first non-flag argument instead of relying on a fixed index:
const firstArg = process.argv.slice(2).find(arg => !arg.startsWith('-'))
Bug
When a global option (e.g.
--use-context,--config-file,--json) is placed before the subcommand name, the lazy-loading logic insrc/cli.tsfails to detect the correct subcommand and registers only the empty stub instead of the full command tree.Steps to reproduce
Expected: command runs normally
Actual:
Root cause
cli.tsusesprocess.argv[2]to identify the first subcommand:When global flags precede the subcommand,
argv[2]is the flag (e.g.--use-context) rather than the subcommand name (cloud), so the full command tree is never loaded.Suggested fix
Scan for the first non-flag argument instead of relying on a fixed index: