idt/installers/
marksman.rs

1use std::path::Path;
2
3use ytil_sys::Arch;
4use ytil_sys::Os;
5use ytil_sys::SysInfo;
6
7use crate::downloaders::curl::CurlDownloaderOption;
8use crate::installers::Installer;
9use crate::installers::SystemDependent;
10
11pub struct Marksman<'a> {
12    pub bin_dir: &'a Path,
13    pub sys_info: &'a SysInfo,
14}
15
16impl SystemDependent for Marksman<'_> {
17    fn target_arch_and_os(&self) -> (&str, &str) {
18        let SysInfo { os, arch } = self.sys_info;
19        let arch_suffix = match (os, arch) {
20            (Os::MacOs, Arch::Arm | Arch::X86) => "",
21            (Os::Linux, Arch::Arm) => "-arm64",
22            (Os::Linux, Arch::X86) => "-x64",
23        };
24        let os = match os {
25            Os::MacOs => "macos",
26            Os::Linux => "linux",
27        };
28        (arch_suffix, os)
29    }
30}
31
32impl Installer for Marksman<'_> {
33    fn bin_name(&self) -> &'static str {
34        "marksman"
35    }
36
37    fn install(&self) -> color_eyre::Result<()> {
38        let (arch, os) = self.target_arch_and_os();
39
40        let target = crate::downloaders::curl::run(
41            &format!(
42                "https://github.com/artempyanykh/{0}/releases/latest/download/{0}-{os}{arch}",
43                self.bin_name()
44            ),
45            &CurlDownloaderOption::WriteTo {
46                dest_path: &self.bin_dir.join(self.bin_name()),
47            },
48        )?;
49
50        ytil_sys::file::chmod_x(&target)?;
51
52        Ok(())
53    }
54}