fix(cli): reject conflicting instance selectors (#2887)

This commit is contained in:
fanyang
2026-11-26 23:25:18 +08:00
committed by GitHub
parent 4356968f0a
commit b82e5946b6
+24 -1
View File
@@ -172,7 +172,12 @@ enum OutputFormat {
#[derive(Parser, Debug)]
struct InstanceSelectArgs {
#[arg(short = 'i', long = "instance-id", help = "the instance id")]
#[arg(
short = 'i',
long = "instance-id",
conflicts_with = "name",
help = "the instance id"
)]
id: Option<uuid::Uuid>,
#[arg(short = 'n', long = "instance-name", help = "the instance name")]
@@ -778,6 +783,24 @@ mod tests {
use super::*;
use easytier::proto::api::instance::PeerConnInfo;
#[test]
fn instance_id_and_name_are_mutually_exclusive() {
let id = "12345678-1234-1234-1234-123456789abc";
let err = Cli::try_parse_from([
"easytier-cli",
"--instance-id",
id,
"--instance-name",
"mesh",
"peer",
])
.unwrap_err();
assert_eq!(err.kind(), clap::error::ErrorKind::ArgumentConflict);
Cli::try_parse_from(["easytier-cli", "--instance-id", id, "peer"]).unwrap();
Cli::try_parse_from(["easytier-cli", "--instance-name", "mesh", "peer"]).unwrap();
}
#[test]
fn dns_commands_parse_and_files_preserve_clear_semantics() {
let cli = Cli::try_parse_from([