Skip to content

Commit

Permalink
merge: #2699
Browse files Browse the repository at this point in the history
2699: fix(si): Change the si launch command to use xdg open functionality r=stack72 a=stack72



Co-authored-by: stack72 <[email protected]>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Aug 24, 2023
2 parents f09dfe1 + 0c0a16d commit c928d0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/si-cli/src/cmd/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use crate::key_management::get_user_email;
use crate::state::AppState;
use crate::{CliResult, SiCliError};
use indicatif::{ProgressBar, ProgressStyle};
use std::thread;
use std::process::Command;
use std::time::Duration;
use std::{env, thread};

impl AppState {
pub async fn launch(&self, launch_metrics: bool) -> CliResult<()> {
Expand All @@ -28,13 +29,22 @@ async fn invoke(launch_metrics: bool, web_host: String, web_port: u32) -> CliRes
check_sdf().await?;
}

println!("Opening URL: {}", path);
match open::that(path.clone()) {
Ok(()) => Ok(()),
Err(_err) => Err(SiCliError::FailToLaunch(path)),
let output = if cfg!(target_os = "macos") {
Command::new("open").arg(path.clone()).output()
} else if cfg!(target_os = "linux") {
Command::new("xdg-open").arg(path.clone()).output()
} else {
// This should NEVER get called but I added it in here just incase
return Err(SiCliError::UnsupportedOperatingSystem(
env::consts::OS.to_string(),
));
};

if let Err(_err) = output {
return Err(SiCliError::FailToLaunch(path));
}
.expect("issue opening url");

println!("Successfully opened URL: {}", path);
Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions lib/si-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub enum SiCliError {
UnableToFetchContainersUpdate(u16),
#[error("unable to fetch si update, status = {0}")]
UnableToFetchSiUpdate(u16),
#[error("unsupported operating system: {0}")]
UnsupportedOperatingSystem(String),
#[error("env var: {0}")]
Var(#[from] VarError),
#[error("web portal is currently offline - please check that the system is running")]
Expand Down

0 comments on commit c928d0f

Please sign in to comment.