Reject unknown arguments instead of starting a second host

Any unrecognized first argument fell through to the server start-up, so a
mistyped or missing subcommand launched a second full host next to the
running service. Print usage and exit 2; help/-h/--help print usage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
VallierDevandClaude Opus 5.5 committed 2026-10-14 23:59:04 +08:00
1 parent d93e42340d
commit c99a587afc
1 file changed
+9
+9
View File
@@ -49,6 +49,15 @@ use webrtc::WebRtcSession;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
// An unknown argument must never fall through to starting a second full host server.
const SUBCOMMANDS: [&str; 8] = ["login", "unlock-check", "desktop-probe", "desktop-video-probe", "wayland-capture",
"wayland-input-probe", "clipboard-acceptance", "portal-acceptance"];
if let Some(arg) = std::env::args().nth(1).filter(|a| !SUBCOMMANDS.contains(&a.as_str())) {
let usage = format!("usage: uuremote-server [{}]\n (no argument: run the host)", SUBCOMMANDS.join(" | "));
if matches!(arg.as_str(), "help" | "-h" | "--help") { println!("{usage}"); return Ok(()); }
eprintln!("unknown argument: {arg}\n{usage}");
std::process::exit(2);
}
if std::env::args().nth(1).as_deref() == Some("clipboard-acceptance") {
return tokio::task::spawn_blocking(clipboard_probe::run).await?.map_err(Into::into);
}