Skip to content

Commit f8c7d99

Browse files
comments
1 parent c6f761c commit f8c7d99

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,32 @@ async fn main() -> anyhow::Result<()> {
309309
fn get_errorchecked_args() -> Cli {
310310
let mut cli = Cli::parse();
311311
let mut command = Cli::command();
312+
// If no interface version is provided, normal behavior.
312313
let Some(interface_version) = &cli.interface_version else {
313314
if !cli.unknown_args.is_empty() {
314315
unknown_arg(&mut command, &cli.unknown_args[0]);
315316
}
316317
return cli;
317318
};
318319
let our_version = Version::parse("1.0.0").expect("valid version");
320+
// Backwards compatibility: if at all possible, the requirement should be kept at ^1.0.0 while retaining semver.
319321
let requirement = VersionReq::parse("^1.0.0").expect("valid version req");
320322
if !requirement.matches(interface_version) {
321323
eprintln!(
322324
"Error: Unsupported interface version {interface_version}. Supported versions: {requirement}",
323325
);
324326
std::process::exit(1);
325327
}
328+
// Forwards compatibility: unknown arguments for a newer version should be ignored rather than erroring.
326329
if !cli.unknown_args.is_empty() {
327330
if *interface_version == our_version {
331+
// If this is the exact same version, unknown args are bad args.
328332
unknown_arg(&mut command, &cli.unknown_args[0]);
329333
} else {
334+
// If this is a future version, unknown args are possibly correct.
335+
// It is a lot more likely to be misinput if the user is writing them (vs automation),
336+
// which is why the behavior is disabled without an explicit interface version,
337+
// since manual usage likely will not involve this flag.
330338
let mut unknown_args = vec![];
331339
while !cli.unknown_args.is_empty() {
332340
let mut prev_unknown_args = mem::take(&mut cli.unknown_args);

0 commit comments

Comments
 (0)