Skip to main content

idt/installers/
harper_ls.rs

1use std::path::Path;
2
3use rootcause::prelude::ResultExt as _;
4
5use crate::Installer;
6
7pub struct HarperLs<'a> {
8    pub bin_dir: &'a Path,
9}
10
11impl Installer for HarperLs<'_> {
12    fn bin_name(&self) -> &'static str {
13        "harper-ls"
14    }
15
16    fn install(&self) -> rootcause::Result<()> {
17        // Installing with `cargo` because I like it this way
18        ytil_cmd::silent_cmd("cargo")
19            .args([
20                "install",
21                self.bin_name(),
22                "--force",
23                "--root",
24                // `--root` automatically append `bin` 🥲
25                self.bin_dir.to_string_lossy().trim_end_matches("bin"),
26            ])
27            .status()
28            .context("failed to spawn cargo install")?
29            .exit_ok()
30            .context("cargo install failed")
31            .attach_with(|| format!("tool={}", self.bin_name()))?;
32
33        ytil_sys::file::chmod_x(self.bin_dir.join(self.bin_name()))?;
34
35        Ok(())
36    }
37}