Skip to content

fix: show 'unknown command' for invalid subcommands#441

Closed
RTCartist wants to merge 3 commits into
MoonshotAI:mainfrom
RTCartist:fix/cli-unknown-subcommand-error
Closed

fix: show 'unknown command' for invalid subcommands#441
RTCartist wants to merge 3 commits into
MoonshotAI:mainfrom
RTCartist:fix/cli-unknown-subcommand-error

Conversation

@RTCartist
Copy link
Copy Markdown

@RTCartist RTCartist commented Jun 4, 2026

Related Issue

Resolve #440

Problem

kimi nonexistent reports error: too many arguments. Expected 0 arguments but got 1. instead of saying the command is unknown. Commander treats the unrecognized word as an excess positional on the root command, which has no argument() defined.

What changed

Add argument('[unknown...]') on the root command only and check the captured value in the action handler. Subcommands keep Commander's default excess-argument validation (catching the codex review feedback — allowExcessArguments(true) at the root would inherit to subcommands and silently accept kimi upgrade extra). Also enable showSuggestionAfterError() for better hints on misspelled options.

Error becomes:

$ kimi nonexistent
error: unknown command 'nonexistent'. Available commands: export, provider, acp, login, doctor, migrate, upgrade.
See 'kimi --help'.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Verification

  • pnpm -C apps/kimi-code exec vitest run test/cli/options.test.ts

Note: PR #442 by @Eric-Song-Nop (the issue reporter) addresses the same issue with a similar approach. Happy to defer to that PR if preferred.

RTCartist added 2 commits June 5, 2026 00:43
…id subcommands

When a user types `kimi nonexistent`, the CLI previously reported
"too many arguments" because Commander treated the unrecognized word
as an excess positional argument. Allow excess arguments on the main
command and check them in the action handler, producing a clear
"unknown command 'nonexistent'" error with a list of available
commands.

Closes MoonshotAI#440
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 4, 2026

🦋 Changeset detected

Latest commit: 3f86303

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0cccd4013

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/kimi-code/src/cli/commands.ts Outdated
.description('The Starting Point for Next-Gen Agents')
.version(version, '-V, --version')
.allowUnknownOption(false)
.allowExcessArguments(true)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep excess-argument checks on subcommands

Because Commander’s .command() copies inherited settings from the parent (cmd.copyInheritedSettings(this)), and that copied set includes _allowExcessArguments, setting this before registering subcommands disables the default excess-argument validation for every subcommand. In the inspected CLI registrations this means commands like kimi upgrade extra or kimi provider list extra now execute and silently ignore the stray operand instead of failing, which is risky for side-effecting subcommands; keep this suppression scoped to the root fallback or reset it on subcommands.

Useful? React with 👍 / 👎.

Replace `allowExcessArguments(true)` (which inherited to all
subcommands) with an explicit `argument('[unknown...]')` on the
root command. Subcommands define their own arguments independently
and retain Commander's default excess-argument validation.
@RTCartist
Copy link
Copy Markdown
Author

Good catch — replaced allowExcessArguments(true) with an explicit argument('[unknown...]') on the root command only. Subcommands define their own arguments independently and retain Commander's default excess-argument validation, so kimi upgrade extra still correctly rejects the stray operand. Fixed in 3f86303.

@RTCartist
Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@liruifengv
Copy link
Copy Markdown
Collaborator

Sorry, we currently do not accept PRs submitted in batches using AI

@liruifengv liruifengv closed this Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

misleading cli output for non-existing subcommand

2 participants