mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-26 14:55:00 +08:00
Compare commits
3 Commits
feat/jobdo
...
feat/jobdo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a533ceba0 | ||
|
|
860f285f70 | ||
|
|
9dd7e79eb2 |
@@ -739,6 +739,9 @@ enum LocalHelpTopic {
|
||||
Meta,
|
||||
Submit,
|
||||
Resume,
|
||||
// #130e-B: help parity — surface-level bugs (plugins, prompt)
|
||||
Plugins,
|
||||
Prompt,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -787,20 +790,20 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
if !rest.is_empty()
|
||||
&& matches!(
|
||||
rest[0].as_str(),
|
||||
"prompt"
|
||||
| "commit"
|
||||
"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, init, state, export,
|
||||
// version, system-prompt, dump-manifests, bootstrap-plan) must
|
||||
// NOT be intercepted here — they handle --help in their own
|
||||
// dispatch paths via parse_local_help_action(). See #141.
|
||||
// the arg to the API should show top-level help instead.
|
||||
// Subcommands that consume their own args (agents, mcp, plugins,
|
||||
// skills) and local help-topic subcommands (status, sandbox,
|
||||
// doctor, init, state, export, version, system-prompt,
|
||||
// dump-manifests, bootstrap-plan, diff, config, help, submit,
|
||||
// resume, prompt) must NOT be intercepted here — they handle
|
||||
// --help in their own dispatch paths via
|
||||
// parse_local_help_action(). See #141, #130c, #130d, #130e.
|
||||
wants_help = true;
|
||||
index += 1;
|
||||
}
|
||||
@@ -1012,7 +1015,18 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
|
||||
match rest[0].as_str() {
|
||||
"dump-manifests" => parse_dump_manifests_args(&rest[1..], output_format),
|
||||
"bootstrap-plan" => Ok(CliAction::BootstrapPlan { output_format }),
|
||||
"bootstrap-plan" => {
|
||||
// #152: bootstrap-plan is a no-arg verb. Reject unexpected suffixes
|
||||
// like `claw bootstrap-plan garbage` that silently accept trailing
|
||||
// args instead of rejecting at parse time.
|
||||
if rest.len() > 1 {
|
||||
return Err(format!(
|
||||
"unrecognized argument `{}` for subcommand `bootstrap-plan`",
|
||||
rest[1]
|
||||
));
|
||||
}
|
||||
Ok(CliAction::BootstrapPlan { output_format })
|
||||
}
|
||||
"agents" => Ok(CliAction::Agents {
|
||||
args: join_optional_args(&rest[1..]),
|
||||
output_format,
|
||||
@@ -1185,7 +1199,16 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
"system-prompt" => parse_system_prompt_args(&rest[1..], output_format),
|
||||
"acp" => parse_acp_args(&rest[1..], output_format),
|
||||
"login" | "logout" => Err(removed_auth_surface_error(rest[0].as_str())),
|
||||
"init" => Ok(CliAction::Init { output_format }),
|
||||
"init" => {
|
||||
// #152: init is a no-arg verb. Reject unexpected suffixes like `claw init foo`.
|
||||
if rest.len() > 1 {
|
||||
return Err(format!(
|
||||
"unrecognized argument `{}` for subcommand `init`",
|
||||
rest[1]
|
||||
));
|
||||
}
|
||||
Ok(CliAction::Init { output_format })
|
||||
}
|
||||
"export" => parse_export_args(&rest[1..], output_format),
|
||||
"prompt" => {
|
||||
let prompt = rest[1..].join(" ");
|
||||
@@ -1286,6 +1309,9 @@ fn parse_local_help_action(rest: &[String]) -> Option<Result<CliAction, String>>
|
||||
"help" => LocalHelpTopic::Meta,
|
||||
"submit" => LocalHelpTopic::Submit,
|
||||
"resume" => LocalHelpTopic::Resume,
|
||||
// #130e-B: help parity — surface fixes
|
||||
"plugins" => LocalHelpTopic::Plugins,
|
||||
"prompt" => LocalHelpTopic::Prompt,
|
||||
_ => return None,
|
||||
};
|
||||
Some(Ok(CliAction::HelpTopic(topic)))
|
||||
@@ -6151,6 +6177,23 @@ fn render_help_topic(topic: LocalHelpTopic) -> String {
|
||||
Requires valid Anthropic credentials (ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY)
|
||||
Related claw submit · claw --resume · /session list"
|
||||
.to_string(),
|
||||
// #130e-B: help topic for `claw plugins --help`.
|
||||
LocalHelpTopic::Plugins => "Plugins
|
||||
Usage claw plugins [list|install|enable|disable|uninstall|update] [<target>]
|
||||
Purpose manage bundled and user plugins from the CLI surface
|
||||
Defaults list (no action prints inventory)
|
||||
Sources .claw/plugins.json, bundled catalog, user-installed
|
||||
Formats text (default), json
|
||||
Related claw mcp · claw skills · /plugins (REPL)"
|
||||
.to_string(),
|
||||
// #130e-B: help topic for `claw prompt --help`.
|
||||
LocalHelpTopic::Prompt => "Prompt
|
||||
Usage claw prompt <prompt-text>
|
||||
Purpose run a single-turn, non-interactive prompt and exit (like --print mode)
|
||||
Flags --model · --allowedTools · --output-format · --compact
|
||||
Requires valid Anthropic credentials (ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY)
|
||||
Related claw submit · claw (bare, interactive REPL)"
|
||||
.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10540,6 +10583,43 @@ mod tests {
|
||||
let resume_h = parse_args(&["resume".to_string(), "-h".to_string()])
|
||||
.expect("resume -h must parse");
|
||||
assert!(matches!(resume_h, CliAction::HelpTopic(LocalHelpTopic::Resume)));
|
||||
// #130e-B: surface-level help fixes for plugins and prompt.
|
||||
// These previously emitted "Unknown action" (plugins) or wrong help (prompt).
|
||||
let plugins_help = parse_args(&[
|
||||
"plugins".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("plugins --help must parse as help action");
|
||||
assert!(
|
||||
matches!(plugins_help, CliAction::HelpTopic(LocalHelpTopic::Plugins)),
|
||||
"#130e-B: plugins --help must route to LocalHelpTopic::Plugins, got: {plugins_help:?}"
|
||||
);
|
||||
let prompt_help = parse_args(&[
|
||||
"prompt".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("prompt --help must parse as help action");
|
||||
assert!(
|
||||
matches!(prompt_help, CliAction::HelpTopic(LocalHelpTopic::Prompt)),
|
||||
"#130e-B: prompt --help must route to LocalHelpTopic::Prompt, got: {prompt_help:?}"
|
||||
);
|
||||
// Short forms
|
||||
let plugins_h = parse_args(&["plugins".to_string(), "-h".to_string()])
|
||||
.expect("plugins -h must parse");
|
||||
assert!(matches!(plugins_h, CliAction::HelpTopic(LocalHelpTopic::Plugins)));
|
||||
let prompt_h = parse_args(&["prompt".to_string(), "-h".to_string()])
|
||||
.expect("prompt -h must parse");
|
||||
assert!(matches!(prompt_h, CliAction::HelpTopic(LocalHelpTopic::Prompt)));
|
||||
// Non-regression: `prompt "actual text"` still parses as Prompt action
|
||||
let prompt_action = parse_args(&[
|
||||
"prompt".to_string(),
|
||||
"hello world".to_string(),
|
||||
])
|
||||
.expect("prompt with real text must parse");
|
||||
assert!(
|
||||
matches!(prompt_action, CliAction::Prompt { ref prompt, .. } if prompt == "hello world"),
|
||||
"#130e-B: prompt with real text must route to Prompt action"
|
||||
);
|
||||
// #147: empty / whitespace-only positional args must be rejected
|
||||
// with a specific error instead of falling through to the prompt
|
||||
// path (where they surface a misleading "missing Anthropic
|
||||
|
||||
Reference in New Issue
Block a user