This repository was archived by the owner on May 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.rs
More file actions
46 lines (37 loc) · 1.44 KB
/
main.rs
File metadata and controls
46 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mod architecture;
mod checker;
mod error;
mod ostype;
use crate::{architecture::Architecture, error::Result, ostype::OsType};
use std::{
env::consts,
io::{self, Write},
process,
};
fn main() -> Result<()> {
let version = "2.0.3";
// create XDG profile
let xdg_dirs = xdg::BaseDirectories::with_profile("editorconfig-checker", version)?;
let architecture = consts::ARCH.parse::<Architecture>()?;
let os_type = consts::OS.parse::<OsType>()?;
// create XDG cache dir in case it does not exist
xdg_dirs.create_cache_directory("")?;
// use XDG cache home as base path
let base_path = xdg_dirs.get_cache_home();
let filename = checker::generate_filename(os_type, architecture);
let tar_path = format!("{}/{}.tar.gz", base_path.display(), filename);
let binary_path = format!("{}/bin/{}", base_path.display(), filename);
if !checker::path_exists(&binary_path) {
let base_url: String = checker::generate_base_url(version);
checker::download(&base_url, base_path.display(), &filename)?;
checker::unpack(&tar_path, &base_path)?;
}
let command = process::Command::new(binary_path)
.args(std::env::args().skip(1))
.output()
.expect("failed to run binary");
let stdout = io::stdout();
let mut stdout = stdout.lock();
writeln!(stdout, "{}", std::str::from_utf8(&command.stdout)?)?;
process::exit(command.status.code().unwrap_or_default());
}