Skip to content

Commit 05b1ddf

Browse files
committed
start: show reset hint when IOTP is completed
1 parent 308c07d commit 05b1ddf

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

packages/cli-rust/src/commands/start.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,11 @@ async fn maybe_print_iotp_info(
13671367
style("Could not retrieve an IOTP from bootstrap state.").yellow()
13681368
);
13691369
println!("Reason: {}", iotp_unavailable_reason(&snapshot));
1370+
if matches!(snapshot.state, IotpState::InactiveCompleted) {
1371+
for line in iotp_reset_hint_lines(!config.is_localhost()) {
1372+
println!("{}", format_iotp_reset_hint_line(&line));
1373+
}
1374+
}
13701375
println!("Fetch logs with: {}", style("occ logs").cyan());
13711376
println!("Try extracting IOTP with:\n {IOTP_FALLBACK_COMMAND}");
13721377
}
@@ -1379,6 +1384,21 @@ fn iotp_unavailable_reason(snapshot: &IotpSnapshot) -> String {
13791384
format!("IOTP state is {}", snapshot.state_label)
13801385
}
13811386

1387+
fn iotp_reset_hint_lines(non_localhost_bind: bool) -> Vec<String> {
1388+
let mut lines = vec!["Reset IOTP: occ reset iotp".to_string()];
1389+
if non_localhost_bind {
1390+
lines.push("Use --force for exposed bind configurations.".to_string());
1391+
}
1392+
lines
1393+
}
1394+
1395+
fn format_iotp_reset_hint_line(line: &str) -> String {
1396+
if let Some(command) = line.strip_prefix("Reset IOTP: ") {
1397+
return format!("{} {}", style("Reset IOTP:").dim(), style(command).cyan());
1398+
}
1399+
style(line).dim().to_string()
1400+
}
1401+
13821402
/// Open browser if requested
13831403
fn open_browser_if_requested(should_open: bool, port: u16, bind_addr: &str) {
13841404
if !should_open {
@@ -1675,6 +1695,19 @@ mod tests {
16751695
assert_eq!(reason, "IOTP state is inactive (users configured)");
16761696
}
16771697

1698+
#[test]
1699+
fn iotp_reset_hint_lines_includes_force_hint_when_exposed() {
1700+
let lines = iotp_reset_hint_lines(true);
1701+
assert_eq!(lines[0], "Reset IOTP: occ reset iotp");
1702+
assert!(lines.iter().any(|line| line.contains("--force")));
1703+
}
1704+
1705+
#[test]
1706+
fn iotp_reset_hint_lines_without_exposed_only_shows_command() {
1707+
let lines = iotp_reset_hint_lines(false);
1708+
assert_eq!(lines, vec!["Reset IOTP: occ reset iotp".to_string()]);
1709+
}
1710+
16781711
#[test]
16791712
fn local_opencode_submodule_requires_rebuild_flag() {
16801713
let args = StartArgs {

0 commit comments

Comments
 (0)