1
use std::ffi::OsStr;
2

            
3
use super::CLI;
4

            
5
pub mod install;
6
pub mod list;
7
pub struct Protontricks;
8

            
9
impl CLI for Protontricks {
10
3
    async fn exec<I, S>(args: I) -> Result<String, String>
11
3
    where
12
3
        I: IntoIterator<Item = S>,
13
3
        S: AsRef<OsStr>,
14
3
    {
15
3
        if Self::is_installed().await {
16
            return super::exec("protontricks", args).await;
17
3
        }
18

            
19
3
        return Err("Please install 'protontricks'!".to_string());
20
3
    }
21

            
22
6
    async fn is_installed() -> bool {
23
6
        super::exec("protontricks", ["--version"]).await.is_ok()
24
6
    }
25

            
26
3
    async fn version() -> Result<String, String> {
27
3
        Self::exec(["--version"]).await
28
3
    }
29
}
30

            
31
#[cfg(test)]
32
mod tests {
33
    use std::env;
34

            
35
    use crate::utils::commands::{protontricks::Protontricks, CLI};
36

            
37
    #[tokio::test]
38
3
    async fn version_should_return_the_version() {
39
3
        assert_eq!(
40
3
            Protontricks::version().await.is_ok(),
41
3
            !env::var("CI").is_ok()
42
3
        );
43
3
    }
44

            
45
    #[tokio::test]
46
3
    async fn is_installed_should_return_false_if_not_installed() {
47
3
        assert_eq!(Protontricks::is_installed().await, !env::var("CI").is_ok());
48
3
    }
49
}