Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/11539-refusal-next-step-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- section: Changed -->
- CLI refusal and argument errors (agent, check, gate, baseline, cache, config, doctor, init, pilot, receipt, policy, swarm and related commands) now name the next step to take, and their baseline entries in `policy/refusal-next-step.d/` are removed (#11713).
226 changes: 136 additions & 90 deletions crates/ripr/src/cli/agent.rs

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions crates/ripr/src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl CliCommand {
Some("--help" | "-h") if wants_all(&command_args) => match command_args.len() {
1 => Ok(Self::HelpAll),
_ => Err(
"usage: ripr --help --all (this route accepts no other arguments)".to_string(),
"usage: ripr --help --all (this route accepts no other arguments); drop the extra arguments, or run `ripr --help` to list commands".to_string(),
),
},
None | Some("--help" | "-h") => Ok(Self::Help),
Expand All @@ -89,7 +89,7 @@ impl CliCommand {
return match command_args.len() {
1 => Ok(Self::HelpAll),
_ => Err(
"usage: ripr help --all (this route accepts no other arguments)"
"usage: ripr help --all (this route accepts no other arguments); drop the extra arguments, or run `ripr --help` to list commands"
.to_string(),
),
};
Expand All @@ -100,7 +100,7 @@ impl CliCommand {
return match command_args.len() {
1 => Ok(Self::HelpJson),
_ => Err(
"usage: ripr help --json (this route accepts no other arguments)"
"usage: ripr help --json (this route accepts no other arguments); drop the extra arguments, or run `ripr --help` to list commands"
.to_string(),
),
};
Expand Down Expand Up @@ -189,7 +189,7 @@ fn help_workflow_command(args: &[String]) -> Result<CliCommand, String> {
[] => Ok(CliCommand::HelpWorkflow(None)),
[name] if !name.starts_with('-') => Ok(CliCommand::HelpWorkflow(Some(name.clone()))),
_ => Err(
"usage: ripr help workflow [<workflow-name>] (this route accepts no flags)".to_string(),
"usage: ripr help workflow [<workflow-name>] (this route accepts no flags); drop the flags, or run `ripr help workflow` to list workflows".to_string(),
),
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ mod tests {
/// usage error naming the accepted form.
#[test]
fn help_all_rejects_trailing_arguments() {
let usage = "usage: ripr help --all (this route accepts no other arguments)";
let usage = "usage: ripr help --all (this route accepts no other arguments); drop the extra arguments, or run `ripr --help` to list commands";
for bad in [
args(&["--all", "check"]),
args(&["--all", "foo", "bar"]),
Expand All @@ -443,7 +443,7 @@ mod tests {
Err(usage.to_string())
);
}
let flag_usage = "usage: ripr --help --all (this route accepts no other arguments)";
let flag_usage = "usage: ripr --help --all (this route accepts no other arguments); drop the extra arguments, or run `ripr --help` to list commands";
assert_eq!(
CliCommand::from_parts(Some("--help"), args(&["--all", "check"])),
Err(flag_usage.to_string())
Expand Down Expand Up @@ -827,7 +827,7 @@ mod tests {
);
// Flag-shaped names and extra arguments are usage errors, keeping the
// failure family distinct from the unknown-workflow family.
let usage = "usage: ripr help workflow [<workflow-name>] (this route accepts no flags)";
let usage = "usage: ripr help workflow [<workflow-name>] (this route accepts no flags); drop the flags, or run `ripr help workflow` to list workflows";
for bad in [
args(&["workflow", "--json"]),
args(&["workflow", "repair-gap", "extra"]),
Expand All @@ -848,7 +848,7 @@ mod tests {
CliCommand::from_parts(Some("help"), args(&["--json"])),
Ok(CliCommand::HelpJson)
);
let usage = "usage: ripr help --json (this route accepts no other arguments)";
let usage = "usage: ripr help --json (this route accepts no other arguments); drop the extra arguments, or run `ripr --help` to list commands";
for bad in [
args(&["--json", "extra"]),
args(&["--json", "--quiet"]),
Expand Down
43 changes: 24 additions & 19 deletions crates/ripr/src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn write_text_file(path: &Path, rendered: &str) -> Result<(), String> {
crate::atomic_file::ensure_relative_output_contained(path)?;
output::file_write::write(path, rendered.as_bytes()).map_err(|err| {
format!(
"write output {} failed: {err}",
"write output {} failed: {err}; check you can write to that path, then rerun",
output::outcome::display_path(path)
)
})
Expand Down Expand Up @@ -3837,15 +3837,15 @@ mod tests {
);
assert_eq!(
reports(&args(&["gap-ledger", "--records"])),
Err("missing value for --records".to_string())
Err("missing value for --records; pass a value right after it".to_string())
);
assert_eq!(
reports(&args(&["gap-ledger", "--repo-exposure"])),
Err("missing value for --repo-exposure".to_string())
Err("missing value for --repo-exposure; pass a value right after it".to_string())
);
assert_eq!(
reports(&args(&["gap-ledger", "--check-output"])),
Err("missing value for --check-output".to_string())
Err("missing value for --check-output; pass a value right after it".to_string())
);
assert_eq!(
reports(&args(&[
Expand Down Expand Up @@ -3906,7 +3906,7 @@ mod tests {
);
assert_eq!(
reports(&args(&["ts-limitations", "--check-output"])),
Err("missing value for --check-output".to_string())
Err("missing value for --check-output; pass a value right after it".to_string())
);
}

Expand Down Expand Up @@ -3986,7 +3986,7 @@ mod tests {
);
assert_eq!(
reports(&args(&["ts-false-actionable", "--corpus"])),
Err("missing value for --corpus".to_string())
Err("missing value for --corpus; pass a value right after it".to_string())
);
}

Expand Down Expand Up @@ -4972,7 +4972,7 @@ mod tests {
);
assert_eq!(
parse_policy_operations_options(&args(&[])),
Err("policy operations requires --policy-readiness <path>".to_string())
Err("policy operations requires --policy-readiness <path>; add `--policy-readiness <path>` to the command".to_string())
);
assert_eq!(
parse_policy_operations_options(&args(&["--policy-readiness", ""])),
Expand All @@ -4984,7 +4984,9 @@ mod tests {
);
assert_eq!(
parse_policy_promotion_options(&args(&[])),
Err("policy promote requires --to <mode>".to_string())
Err(
"policy promote requires --to <mode>; add `--to <mode>` to the command".to_string()
)
);
assert_eq!(
parse_policy_promotion_options(&args(&["--to", "strict"])),
Expand All @@ -5002,7 +5004,7 @@ mod tests {
);
assert_eq!(
parse_policy_promotion_options(&args(&["--to", "visible-only"])),
Err("policy promote requires --operations <path>".to_string())
Err("policy promote requires --operations <path>; add `--operations <path>` to the command".to_string())
);
assert_eq!(
parse_policy_promotion_options(&args(&["--to", "visible-only", "--operations", ""])),
Expand All @@ -5017,7 +5019,7 @@ mod tests {
);
assert_eq!(
parse_policy_preview_promotion_options(&args(&[])),
Err("policy preview-promote requires --language <language>".to_string())
Err("policy preview-promote requires --language <language>; add `--language <language>` to the command".to_string())
);
assert_eq!(
parse_policy_preview_promotion_options(&args(&["--language", "ruby"])),
Expand All @@ -5035,7 +5037,7 @@ mod tests {
);
assert_eq!(
parse_policy_preview_promotion_options(&args(&["--language", "typescript"])),
Err("policy preview-promote requires --class <class>".to_string())
Err("policy preview-promote requires --class <class>; add `--class <class>` to the command".to_string())
);
assert_eq!(
parse_policy_preview_promotion_options(&args(&[
Expand Down Expand Up @@ -5084,7 +5086,10 @@ mod tests {
);
assert_eq!(
parse_policy_history_options(&args(&[])),
Err("policy history requires --current <path>".to_string())
Err(
"policy history requires --current <path>; add `--current <path>` to the command"
.to_string()
)
);
assert_eq!(
parse_policy_history_options(&args(&["--current", ""])),
Expand Down Expand Up @@ -7875,11 +7880,11 @@ language = "rust"
fn init_requires_root_value() {
assert_eq!(
init(&args(&["--root"])),
Err("missing value for --root".to_string())
Err("missing value for --root; pass a value right after it".to_string())
);
assert_eq!(
init(&args(&["--ci"])),
Err("missing value for --ci".to_string())
Err("missing value for --ci; pass a value right after it".to_string())
);
}

Expand Down Expand Up @@ -8986,23 +8991,23 @@ language = "rust"
fn explain_requires_values_for_value_flags() {
assert_eq!(
explain(&args(&["--root"])),
Err("missing value for --root".to_string())
Err("missing value for --root; pass a value right after it".to_string())
);
assert_eq!(
explain(&args(&["--base"])),
Err("missing value for --base".to_string())
Err("missing value for --base; pass a value right after it".to_string())
);
assert_eq!(
explain(&args(&["--diff"])),
Err("missing value for --diff".to_string())
Err("missing value for --diff; pass a value right after it".to_string())
);
assert_eq!(
explain(&args(&["--perl-facts"])),
Err("missing value for --perl-facts".to_string())
Err("missing value for --perl-facts; pass a value right after it".to_string())
);
assert_eq!(
explain(&args(&["--suppression-policy"])),
Err("missing value for --suppression-policy".to_string())
Err("missing value for --suppression-policy; pass a value right after it".to_string())
);
}

Expand Down
Loading
Loading