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
47
48
49
50
51
52
53
54
55
56
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use path_slash::PathBufExt;
pub fn command(command: &mut Command, description: &str) -> anyhow::Result<()> {
let status = command
.status()
.map_err(|error| anyhow::anyhow!("{} process: {}", description, error))?;
if !status.success() {
anyhow::bail!("{} failed", description);
}
Ok(())
}
pub fn absolute_path<P: AsRef<Path>>(path: P) -> anyhow::Result<PathBuf> {
let mut full_path = std::env::current_dir()?;
full_path.push(path);
Ok(full_path)
}
pub fn path_windows_to_unix<P: AsRef<Path> + PathBufExt>(path: P) -> anyhow::Result<PathBuf> {
path.to_slash()
.map(|pathbuf| PathBuf::from(pathbuf.to_string()))
.ok_or_else(|| anyhow::anyhow!("Windows-to-Unix path conversion error"))
}
pub fn check_presence(name: &str) -> anyhow::Result<()> {
let status = Command::new("which")
.arg(name)
.status()
.map_err(|error| anyhow::anyhow!("`which {}` process: {}", name, error))?;
if !status.success() {
anyhow::bail!("Tool `{}` is missing. Please install", name);
}
Ok(())
}