mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-09 17:44:50 +08:00
fix(cli): intercept --help for prompt/login/logout/version subcommands before API dispatch
'claw prompt --help' was triggering an API call instead of showing help because --help was parsed as part of the prompt args. Now '--help' after known pass-through subcommands (prompt, login, logout, version, state, init, export, commit, pr, issue) sets wants_help=true and shows the top-level help page. Subcommands that consume their own args (agents, mcp, plugins, skills) and local help-topic subcommands (status, sandbox, doctor) are excluded from this interception so their existing --help handling is preserved. 156 CLI tests pass, fmt clean.
This commit is contained in:
@@ -382,7 +382,7 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
let mut compact = false;
|
||||
let mut base_commit: Option<String> = None;
|
||||
let mut reasoning_effort: Option<String> = None;
|
||||
let mut rest = Vec::new();
|
||||
let mut rest: Vec<String> = Vec::new();
|
||||
let mut index = 0;
|
||||
|
||||
while index < args.len() {
|
||||
@@ -391,6 +391,31 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
wants_help = true;
|
||||
index += 1;
|
||||
}
|
||||
"--help" | "-h"
|
||||
if !rest.is_empty()
|
||||
&& matches!(
|
||||
rest[0].as_str(),
|
||||
"prompt"
|
||||
| "login"
|
||||
| "logout"
|
||||
| "version"
|
||||
| "state"
|
||||
| "init"
|
||||
| "export"
|
||||
| "commit"
|
||||
| "pr"
|
||||
| "issue"
|
||||
) =>
|
||||
{
|
||||
// `--help` following a subcommand that would otherwise forward
|
||||
// the arg to the API (e.g. `claw prompt --help`) should show
|
||||
// top-level help instead. Subcommands that consume their own
|
||||
// args (agents, mcp, plugins, skills) and local help-topic
|
||||
// subcommands (status, sandbox, doctor) must NOT be intercepted
|
||||
// here — they handle --help in their own dispatch paths.
|
||||
wants_help = true;
|
||||
index += 1;
|
||||
}
|
||||
"--version" | "-V" => {
|
||||
wants_version = true;
|
||||
index += 1;
|
||||
|
||||
Reference in New Issue
Block a user