-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add the HomeBrew Package Manager
- Loading branch information
Showing
6 changed files
with
119 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::collections::{BTreeMap, BTreeSet}; | ||
|
||
use color_eyre::Result; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::cmd::{command_found, run_command, run_command_for_stdout}; | ||
use crate::prelude::*; | ||
|
||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, derive_more::Display)] | ||
pub struct Brew; | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct BrewQueryInfo {} | ||
|
||
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | ||
pub struct BrewInstallOptions {} | ||
|
||
impl Backend for Brew { | ||
type QueryInfo = BrewQueryInfo; | ||
type InstallOptions = BrewInstallOptions; | ||
|
||
fn map_managed_packages( | ||
packages: BTreeMap<String, Self::InstallOptions>, | ||
_: &Config, | ||
) -> Result<BTreeMap<String, Self::InstallOptions>> { | ||
Ok(packages) | ||
} | ||
|
||
fn query_installed_packages(_: &Config) -> Result<BTreeMap<String, Self::QueryInfo>> { | ||
if !command_found("brew") { | ||
return Ok(BTreeMap::new()); | ||
} | ||
|
||
let explicit = run_command_for_stdout( | ||
["brew", "list", "-1", "--quiet", "--installed-on-request"], | ||
Perms::Same, | ||
)?; | ||
|
||
Ok(explicit | ||
.lines() | ||
.map(|x| (x.to_string(), BrewQueryInfo {})) | ||
.collect()) | ||
} | ||
|
||
fn install_packages( | ||
packages: &BTreeMap<String, Self::InstallOptions>, | ||
_: bool, | ||
_: &Config, | ||
) -> Result<()> { | ||
if !packages.is_empty() { | ||
run_command( | ||
["brew", "install"] | ||
.into_iter() | ||
.chain(packages.keys().map(String::as_str)), | ||
Perms::Same, | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn remove_packages(packages: &BTreeSet<String>, _: bool, _: &Config) -> Result<()> { | ||
if !packages.is_empty() { | ||
run_command( | ||
["brew", "remove"] | ||
.into_iter() | ||
.chain(packages.iter().map(String::as_str)), | ||
Perms::Same, | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters