From a1f288664725b8639f581431e504704d583aa817 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 30 Oct 2026 03:44:25 -0700 Subject: [PATCH] vector: accept Go-style single-dash long flags (#12247) --- seaweed-vector/crates/server/src/main.rs | 31 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/seaweed-vector/crates/server/src/main.rs b/seaweed-vector/crates/server/src/main.rs index de52878e47..15adc1047f 100644 --- a/seaweed-vector/crates/server/src/main.rs +++ b/seaweed-vector/crates/server/src/main.rs @@ -21,11 +21,11 @@ struct Args { listen: String, /// object_store option fallback for deployments that vend no credentials: /// key=value, repeatable. - #[arg(long = "storage-option", value_parser = parse_option)] + #[arg(long = "storage-option", alias = "storage.option", value_parser = parse_option)] storage_options: Vec<(String, String)>, /// Comma-separated master addresses to register this server with; the /// gateway discovers it via ListClusterNodes(client_type=vector). - #[arg(long, env = "WEED_VECTOR_MASTERS")] + #[arg(long, alias = "master", env = "WEED_VECTOR_MASTERS")] masters: Option, } @@ -35,6 +35,31 @@ fn parse_option(s: &str) -> Result<(String, String), String> { .ok_or_else(|| "expected key=value".to_string()) } +// weed tools take Go-style single-dash long flags; normalize_args converts +// any -flag to --flag — the same normalization weed-volume's config.rs does — +// so -master and --masters parse the same. The masters field carries the +// singular alias clap-side. +fn normalize_args(args: Vec) -> Vec { + let mut args = args; + let mut i = 1; // skip args[0] (binary name) + while i < args.len() { + let arg = &args[i]; + if arg == "--" { + break; + } + if arg.starts_with("--") || !arg.starts_with('-') { + i += 1; + continue; + } + let without_dash = &arg[1..]; + if without_dash.len() > 1 && !without_dash.starts_with(|c: char| c.is_ascii_digit()) { + args[i] = format!("-{}", arg); + } + i += 1; + } + args +} + /// A wildcard listen address is not reachable for peers; derive the outbound /// IP toward the first master instead — the address the master sees anyway. fn advertised_addr(listen: &str, masters: &[String]) -> String { @@ -73,7 +98,7 @@ fn advertised_addr(listen: &str, masters: &[String]) -> String { #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt::init(); - let args = Args::parse(); + let args = Args::parse_from(normalize_args(std::env::args().collect())); if let Some(masters) = &args.masters { let masters: Vec = masters.split(',').map(|s| s.trim().to_string()).collect(); let advertise = advertised_addr(&args.listen, &masters);