use command::{Command, CommandResult};
use error::Result;
use host::Host;
use super::*;
pub struct Pkg;
impl Provider for Pkg {
fn get_providers(&self) -> Providers {
Providers::Pkg
}
fn is_active(&self, host: &mut Host) -> Result<bool> {
let cmd = Command::new("type pkg");
let result = try!(cmd.exec(host));
Ok(result.exit_code == 0)
}
fn is_installed(&self, host: &mut Host, name: &str) -> Result<bool> {
let cmd = Command::new(&format!("pkg query \"%n\" {}", name));
let result = try!(cmd.exec(host));
Ok(result.exit_code == 0)
}
fn install(&self, host: &mut Host, name: &str) -> Result<CommandResult> {
let cmd = Command::new(&format!("env ASSUME_ALWAYS_YES=YES pkg install {}", name));
cmd.exec(host)
}
fn uninstall(&self, host: &mut Host, name: &str) -> Result<CommandResult> {
let cmd = Command::new(&format!("env ASSUME_ALWAYS_YES=YES pkg delete {}", name));
cmd.exec(host)
}
}