mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-26 20:25:00 +08:00
Compare commits
2 Commits
feat/jobdo
...
feat/jobdo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19638a015e | ||
|
|
83f744adf0 |
@@ -731,6 +731,10 @@ enum LocalHelpTopic {
|
||||
SystemPrompt,
|
||||
DumpManifests,
|
||||
BootstrapPlan,
|
||||
// #130c: help parity for `claw diff --help`
|
||||
Diff,
|
||||
// #130d: help parity for `claw config --help`
|
||||
Config,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -1044,6 +1048,10 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
// which is synthetic friction. Accepts an optional section name
|
||||
// (env|hooks|model|plugins) matching the slash command shape.
|
||||
"config" => {
|
||||
// #130d: accept --help / -h and route to help topic instead of silently ignoring
|
||||
if rest.len() >= 2 && is_help_flag(&rest[1]) {
|
||||
return Ok(CliAction::HelpTopic(LocalHelpTopic::Config));
|
||||
}
|
||||
let tail = &rest[1..];
|
||||
let section = tail.first().cloned();
|
||||
if tail.len() > 1 {
|
||||
@@ -1061,6 +1069,12 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
// #146: `diff` is pure-local (shells out to `git diff --cached` +
|
||||
// `git diff`). No session needed to inspect the working tree.
|
||||
"diff" => {
|
||||
// #130c: accept --help / -h as first argument and route to help topic,
|
||||
// matching the behavior of status/sandbox/doctor/etc.
|
||||
// Without this guard, `claw diff --help` was rejected as extra arguments.
|
||||
if rest.len() == 2 && is_help_flag(&rest[1]) {
|
||||
return Ok(CliAction::HelpTopic(LocalHelpTopic::Diff));
|
||||
}
|
||||
if rest.len() > 1 {
|
||||
return Err(format!(
|
||||
"unexpected extra arguments after `claw diff`: {}",
|
||||
@@ -1260,6 +1274,10 @@ fn parse_local_help_action(rest: &[String]) -> Option<Result<CliAction, String>>
|
||||
"system-prompt" => LocalHelpTopic::SystemPrompt,
|
||||
"dump-manifests" => LocalHelpTopic::DumpManifests,
|
||||
"bootstrap-plan" => LocalHelpTopic::BootstrapPlan,
|
||||
// #130c: help parity for `claw diff --help`
|
||||
"diff" => LocalHelpTopic::Diff,
|
||||
// #130d: help parity for `claw config --help`
|
||||
"config" => LocalHelpTopic::Config,
|
||||
_ => return None,
|
||||
};
|
||||
Some(Ok(CliAction::HelpTopic(topic)))
|
||||
@@ -6083,6 +6101,24 @@ fn render_help_topic(topic: LocalHelpTopic) -> String {
|
||||
Formats text (default), json
|
||||
Related claw doctor · claw status"
|
||||
.to_string(),
|
||||
// #130c: help topic for `claw diff --help`.
|
||||
LocalHelpTopic::Diff => "Diff
|
||||
Usage claw diff [--output-format <format>]
|
||||
Purpose show local git staged + unstaged changes for the current workspace
|
||||
Requires workspace must be inside a git repository
|
||||
Output unified diff (text) or structured diff object (json)
|
||||
Formats text (default), json
|
||||
Related claw status · claw config"
|
||||
.to_string(),
|
||||
// #130d: help topic for `claw config --help`.
|
||||
LocalHelpTopic::Config => "Config
|
||||
Usage claw config [--cwd <path>] [--output-format <format>]
|
||||
Purpose merge and display the resolved .claw.json / settings.json configuration
|
||||
Options --cwd overrides the workspace directory for config lookup
|
||||
Output loaded files and merged key-value pairs (text) or JSON object (json)
|
||||
Formats text (default), json
|
||||
Related claw status · claw doctor · claw init"
|
||||
.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10352,6 +10388,85 @@ mod tests {
|
||||
"filesystem_io_error",
|
||||
"#130b: enriched messages must be classifier-recognizable"
|
||||
);
|
||||
// #130c: `claw diff --help` must route to help topic, not reject as extra args.
|
||||
// Regression: `diff` was the outlier among local introspection commands
|
||||
// (status/config/mcp all accepted --help) because its parser arm rejected
|
||||
// all extra args before help detection could run.
|
||||
let diff_help_action = parse_args(&[
|
||||
"diff".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("diff --help must parse as help action");
|
||||
assert!(
|
||||
matches!(diff_help_action, CliAction::HelpTopic(LocalHelpTopic::Diff)),
|
||||
"#130c: diff --help must route to LocalHelpTopic::Diff, got: {diff_help_action:?}"
|
||||
);
|
||||
let diff_h_action = parse_args(&[
|
||||
"diff".to_string(),
|
||||
"-h".to_string(),
|
||||
])
|
||||
.expect("diff -h must parse as help action");
|
||||
assert!(
|
||||
matches!(diff_h_action, CliAction::HelpTopic(LocalHelpTopic::Diff)),
|
||||
"#130c: diff -h (short form) must route to LocalHelpTopic::Diff"
|
||||
);
|
||||
// #130c: bare `claw diff` still routes to Diff action, not help.
|
||||
let diff_action = parse_args(&[
|
||||
"diff".to_string(),
|
||||
])
|
||||
.expect("bare diff must parse as diff action");
|
||||
assert!(
|
||||
matches!(diff_action, CliAction::Diff { .. }),
|
||||
"#130c: bare diff must still route to Diff action, got: {diff_action:?}"
|
||||
);
|
||||
// #130c: unknown args still rejected (non-regression).
|
||||
let diff_bad_arg = parse_args(&[
|
||||
"diff".to_string(),
|
||||
"foo".to_string(),
|
||||
])
|
||||
.expect_err("diff foo must still be rejected as extra args");
|
||||
assert!(
|
||||
diff_bad_arg.contains("unexpected extra arguments"),
|
||||
"#130c: diff with unknown arg must still error, got: {diff_bad_arg}"
|
||||
);
|
||||
// #130d: `claw config --help` must route to help topic, not silently run config.
|
||||
let config_help_action = parse_args(&[
|
||||
"config".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("config --help must parse as help action");
|
||||
assert!(
|
||||
matches!(config_help_action, CliAction::HelpTopic(LocalHelpTopic::Config)),
|
||||
"#130d: config --help must route to LocalHelpTopic::Config, got: {config_help_action:?}"
|
||||
);
|
||||
let config_h_action = parse_args(&[
|
||||
"config".to_string(),
|
||||
"-h".to_string(),
|
||||
])
|
||||
.expect("config -h must parse as help action");
|
||||
assert!(
|
||||
matches!(config_h_action, CliAction::HelpTopic(LocalHelpTopic::Config)),
|
||||
"#130d: config -h (short form) must route to LocalHelpTopic::Config"
|
||||
);
|
||||
// #130d: bare `claw config` still routes to Config action with no section
|
||||
let config_action = parse_args(&[
|
||||
"config".to_string(),
|
||||
])
|
||||
.expect("bare config must parse as config action");
|
||||
assert!(
|
||||
matches!(config_action, CliAction::Config { section: None, .. }),
|
||||
"#130d: bare config must still route to Config action with section=None"
|
||||
);
|
||||
// #130d: config with section still works (non-regression)
|
||||
let config_section = parse_args(&[
|
||||
"config".to_string(),
|
||||
"permissions".to_string(),
|
||||
])
|
||||
.expect("config permissions must parse");
|
||||
assert!(
|
||||
matches!(config_section, CliAction::Config { section: Some(ref s), .. } if s == "permissions"),
|
||||
"#130d: config with section must still work"
|
||||
);
|
||||
// #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