Move install_cli function to a seperate crate
Add install cli button to welcome experience Add toast pop ups for CLI installation status
This commit is contained in:
parent
1f6bd0ea77
commit
8db7e17ac5
12 changed files with 142 additions and 64 deletions
18
crates/install_cli/Cargo.toml
Normal file
18
crates/install_cli/Cargo.toml
Normal file
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "install_cli"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
path = "src/install_cli.rs"
|
||||
|
||||
[features]
|
||||
test-support = []
|
||||
|
||||
[dependencies]
|
||||
smol = "1.2.5"
|
||||
anyhow = "1.0.38"
|
||||
log = "0.4"
|
||||
gpui = { path = "../gpui" }
|
||||
util = { path = "../util" }
|
56
crates/install_cli/src/install_cli.rs
Normal file
56
crates/install_cli/src/install_cli.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::{Result, anyhow};
|
||||
use gpui::{AsyncAppContext, actions};
|
||||
use util::ResultExt;
|
||||
|
||||
actions!(cli, [ Install ]);
|
||||
|
||||
|
||||
pub async fn install_cli(cx: &AsyncAppContext) -> Result<()> {
|
||||
let cli_path = cx.platform().path_for_auxiliary_executable("cli")?;
|
||||
let link_path = Path::new("/usr/local/bin/zed");
|
||||
let bin_dir_path = link_path.parent().unwrap();
|
||||
|
||||
// Don't re-create symlink if it points to the same CLI binary.
|
||||
if smol::fs::read_link(link_path).await.ok().as_ref() == Some(&cli_path) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// If the symlink is not there or is outdated, first try replacing it
|
||||
// without escalating.
|
||||
smol::fs::remove_file(link_path).await.log_err();
|
||||
if smol::fs::unix::symlink(&cli_path, link_path)
|
||||
.await
|
||||
.log_err()
|
||||
.is_some()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// The symlink could not be created, so use osascript with admin privileges
|
||||
// to create it.
|
||||
let status = smol::process::Command::new("osascript")
|
||||
.args([
|
||||
"-e",
|
||||
&format!(
|
||||
"do shell script \" \
|
||||
mkdir -p \'{}\' && \
|
||||
ln -sf \'{}\' \'{}\' \
|
||||
\" with administrator privileges",
|
||||
bin_dir_path.to_string_lossy(),
|
||||
cli_path.to_string_lossy(),
|
||||
link_path.to_string_lossy(),
|
||||
),
|
||||
])
|
||||
.stdout(smol::process::Stdio::inherit())
|
||||
.stderr(smol::process::Stdio::inherit())
|
||||
.output()
|
||||
.await?
|
||||
.status;
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("error running osascript"))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue