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
57
58
59
60
61
62
use std::error::Error;

use package::PACKAGE_MANAGERS; use util::has_binary;
pub mod cargo;
pub mod dirs;
pub mod package;
pub mod symlinks;
pub mod script;
pub mod util;

pub use cargo::CargoInstall;
pub use dirs::EnsureDirs;
pub use package::{Package, PackageManager};
pub use symlinks::Symlinks;
pub use script::Script;

pub use dotinstall_macro::installer;


#[macro_use]
extern crate tracing;

#[macro_use]
extern crate duct;

/// Context regarding the system this is being run on
pub struct Context {
    package_manager: PackageManager,
}

impl Context {
    pub fn init() -> Self {
        let package_manager = PACKAGE_MANAGERS
            .iter()
            .find(|p| has_binary(p.executable()).unwrap())
            .expect("No suitable package managers found");

        Self { package_manager: *package_manager }
    }
}

pub trait Installable {
    fn install(&self, ctx: &Context) -> Result<(), Box<dyn Error>>;
}

impl Installable for Vec<Package> {
    fn install(&self, ctx: &Context) -> Result<(), Box<dyn Error>> {
        for package in self {
            package.install(ctx)?;
        }

        Ok(())
    }
}

#[cfg(test)]
#[test]
fn ui() {
    let t = trybuild::TestCases::new();
    t.pass("testing/ui/pass/*.rs");
    t.compile_fail("testing/ui/fail/*.rs");
}