Skip to content

Commit 004df28

Browse files
committed
restore arg parsing
1 parent 63a1ab1 commit 004df28

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3119,7 +3119,6 @@ name = "dimos-viewer"
31193119
version = "0.30.0-alpha.6"
31203120
dependencies = [
31213121
"bincode",
3122-
"clap",
31233122
"futures-util",
31243123
"mimalloc",
31253124
"rerun",

dimos/src/viewer.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,36 @@ impl eframe::App for DimosApp {
5050
}
5151
}
5252

53+
/// Extract `--ws-url <value>` from args, returning (ws_url, remaining_args).
54+
/// This lets us handle our custom flag without conflicting with Rerun's own arg parsing.
55+
fn extract_ws_url(args: Vec<String>) -> (Option<String>, Vec<String>) {
56+
let mut ws_url = None;
57+
let mut remaining = Vec::with_capacity(args.len());
58+
let mut iter = args.into_iter();
59+
while let Some(arg) = iter.next() {
60+
if arg == "--ws-url" {
61+
ws_url = iter.next();
62+
} else if let Some(val) = arg.strip_prefix("--ws-url=") {
63+
ws_url = Some(val.to_string());
64+
} else {
65+
remaining.push(arg);
66+
}
67+
}
68+
(ws_url, remaining)
69+
}
70+
5371
fn main() -> Result<(), Box<dyn std::error::Error>> {
5472
let main_thread_token = re_viewer::MainThreadToken::i_promise_i_am_on_the_main_thread();
5573
let build_info = re_viewer::build_info();
5674

75+
// Extract --ws-url before passing remaining args to Rerun
76+
let (ws_url_arg, rerun_args) = extract_ws_url(std::env::args().collect());
77+
5778
// Connect WebSocket publisher for click/keyboard events
58-
let ws_url = std::env::var("DIMOS_VIEWER_WS_URL")
59-
.unwrap_or_else(|_| DEFAULT_WS_URL.to_string());
79+
// Priority: --ws-url flag > DIMOS_VIEWER_WS_URL env var > default
80+
let ws_url = ws_url_arg
81+
.or_else(|| std::env::var("DIMOS_VIEWER_WS_URL").ok())
82+
.unwrap_or_else(|| DEFAULT_WS_URL.to_string());
6083
let ws_publisher = WsPublisher::connect(ws_url.clone());
6184
re_log::info!("WebSocket client connecting to {ws_url}");
6285

@@ -142,7 +165,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
142165
main_thread_token,
143166
build_info,
144167
rerun::CallSource::Cli,
145-
std::env::args(),
168+
rerun_args.into_iter(),
146169
Some(wrapper),
147170
Some(startup_patch),
148171
)?;

0 commit comments

Comments
 (0)