idt/installers/
starship.rs1use std::path::Path;
2
3use rootcause::prelude::ResultExt as _;
4use ytil_cmd::CmdExt as _;
5use ytil_cmd::silent_cmd;
6
7use crate::Installer;
8
9pub struct Starship<'a> {
10 pub dev_tools_dir: &'a Path,
11 pub bin_dir: &'a Path,
12}
13
14impl Installer for Starship<'_> {
15 fn bin_name(&self) -> &'static str {
16 "starship"
17 }
18
19 fn install(&self) -> rootcause::Result<()> {
20 let source_dir = self.dev_tools_dir.join(self.bin_name()).join("source");
21 let cargo_target = self.dev_tools_dir.join("cargo-target");
22
23 silent_cmd("sh")
24 .args([
25 "-c",
26 &format!(
27 r#"
28 ([ ! -d "{0}" ] && \
29 git clone --depth=1 https://github.com/starship/starship.git {0} || true) && \
30 cd {0} && \
31 git fetch origin master --depth=1 && \
32 git checkout origin/master && \
33 CARGO_TARGET_DIR={1} cargo build --release
34 "#,
35 source_dir.display(),
36 cargo_target.display(),
37 ),
38 ])
39 .status()
40 .context("failed to spawn build command")?
41 .exit_ok()
42 .context("build failed")
43 .attach_with(|| format!("tool={}", self.bin_name()))
44 .attach_with(|| format!("source_dir={}", source_dir.display()))?;
45
46 let target = cargo_target.join("release").join(self.bin_name());
47 ytil_sys::file::ln_sf(&target, &self.bin_dir.join(self.bin_name()))?;
48 ytil_sys::file::chmod_x(&target)?;
49
50 Ok(())
51 }
52
53 fn health_check(&self) -> Option<rootcause::Result<String>> {
54 let res = std::process::Command::new(self.bin_name())
57 .env("TERM", "xterm-256color")
58 .args(["--version"])
59 .exec()
60 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
61 .map_err(From::from);
62 Some(res)
63 }
64
65 fn should_verify_checksum(&self) -> bool {
66 false
67 }
68}