Skip to main content

idt/installers/
taplo.rs

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