Skip to content

Commit 25a5ce5

Browse files
committed
add to --ws-url help properly
1 parent 004df28 commit 25a5ce5

4 files changed

Lines changed: 29 additions & 25 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,6 +3119,7 @@ name = "dimos-viewer"
31193119
version = "0.30.0-alpha.6"
31203120
dependencies = [
31213121
"bincode",
3122+
"clap",
31223123
"futures-util",
31233124
"mimalloc",
31243125
"rerun",

crates/top/rerun/src/commands/entrypoint.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ When persisted, the state will be stored at the following locations:
196196
#[clap(long)]
197197
pub follow: bool,
198198

199+
/// WebSocket server URL for publishing viewer interaction events
200+
/// (clicks, keyboard teleop commands).
201+
///
202+
/// The viewer connects as a WebSocket client to this URL and sends
203+
/// JSON events. Used by DimOS for click-to-navigate and WASD teleop.
204+
///
205+
/// Also configurable via the DIMOS_VIEWER_WS_URL environment variable.
206+
/// CLI flag takes priority over the environment variable.
207+
#[clap(long, default_value = "ws://127.0.0.1:3030/ws")]
208+
pub ws_url: String,
209+
199210
/// The number of compute threads to use.
200211
///
201212
/// If zero, the same number of threads as the number of cores will be used.

dimos/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rerun = { path = "../crates/top/rerun", default-features = false, features = [
2727
] }
2828

2929
bincode.workspace = true
30+
clap.workspace = true
3031
futures-util.workspace = true
3132
mimalloc.workspace = true
3233
serde = { workspace = true, features = ["derive"] }

dimos/src/viewer.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,27 @@ 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-
7153
fn main() -> Result<(), Box<dyn std::error::Error>> {
7254
let main_thread_token = re_viewer::MainThreadToken::i_promise_i_am_on_the_main_thread();
7355
let build_info = re_viewer::build_info();
7456

75-
// Extract --ws-url before passing remaining args to Rerun
76-
let (ws_url_arg, rerun_args) = extract_ws_url(std::env::args().collect());
57+
// Parse args (including --ws-url) via Rerun's clap Args, without consuming them.
58+
// We peek at the parsed value, then pass the original args to run_with_app_wrapper
59+
// which will parse them again.
60+
let parsed: rerun::RerunArgs = clap::Parser::parse();
61+
let ws_url = if std::env::var("DIMOS_VIEWER_WS_URL").is_ok() {
62+
// Env var overrides default but not an explicit CLI flag.
63+
// If the parsed value equals the default, check the env var.
64+
if parsed.ws_url == DEFAULT_WS_URL {
65+
std::env::var("DIMOS_VIEWER_WS_URL").unwrap()
66+
} else {
67+
parsed.ws_url.clone()
68+
}
69+
} else {
70+
parsed.ws_url.clone()
71+
};
7772

7873
// Connect WebSocket publisher for click/keyboard events
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());
8374
let ws_publisher = WsPublisher::connect(ws_url.clone());
8475
re_log::info!("WebSocket client connecting to {ws_url}");
8576

@@ -165,7 +156,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
165156
main_thread_token,
166157
build_info,
167158
rerun::CallSource::Cli,
168-
rerun_args.into_iter(),
159+
std::env::args(),
169160
Some(wrapper),
170161
Some(startup_patch),
171162
)?;

0 commit comments

Comments
 (0)