Skip to content

Commit

Permalink
Merge pull request #53 from mikaoelitiana/feat-homebrew-version
Browse files Browse the repository at this point in the history
feat: create_install_command fn + tests
  • Loading branch information
tsirysndr authored Apr 3, 2024
2 parents 3ed6f1b + 70e9cfa commit aacf0b4
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 8 deletions.
63 changes: 56 additions & 7 deletions crates/pkgs/src/homebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ impl Homebrew {
pub fn new() -> Self {
Self {}
}
}

impl PackageManager for Homebrew {
fn install(&self, name: &str) -> Result<(), Error> {
self.setup()?;
let mut child = Command::new("sh")
pub fn create_install_command(&self, name: &str) -> Command {
let mut command = Command::new("sh");
command
.arg("-c")
.arg(format!("brew install {}", name))
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()?;
.stderr(Stdio::inherit());
command
}
}

impl Default for Homebrew {
fn default() -> Self {
Self::new()
}
}

impl PackageManager for Homebrew {
fn install(&self, name: &str) -> Result<(), Error> {
self.setup()?;
let mut child = self.create_install_command(name).spawn()?;
child.wait()?;
Ok(())
}
Expand Down Expand Up @@ -56,3 +67,41 @@ impl PackageManager for Homebrew {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_create_child_command_with_version() {
let homebrew = Homebrew::new();
let command = homebrew.create_install_command("[email protected]");
assert_eq!(command.get_args().len(), 2);
assert_eq!(
command.get_args().last().unwrap().to_string_lossy(),
"brew install [email protected]"
);
}

#[test]
fn test_create_child_command_without_version() {
let homebrew = Homebrew::new();
let command = homebrew.create_install_command("neovim");
assert_eq!(command.get_args().len(), 2);
assert_eq!(
command.get_args().last().unwrap().to_string_lossy(),
"brew install neovim"
);
}

#[test]
fn test_create_child_command_with_head() {
let homebrew = Homebrew::new();
let command = homebrew.create_install_command("neovim --HEAD");
assert_eq!(command.get_args().len(), 2);
assert_eq!(
command.get_args().last().unwrap().to_string_lossy(),
"brew install neovim --HEAD"
);
}
}
8 changes: 7 additions & 1 deletion demo/envhub.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ envs {
EDITOR = "vim"
}

homebrew {
packages = [
"neovim --HEAD"
]
}

file ".screenrc" {
source = "dotfiles/.screenrc"
}
Expand All @@ -18,4 +24,4 @@ file ".gradle/gradle.properties" {
content = "org.gradle.daemon=true"
}

secrets = ["CLOUDFLARE_ROOT_KEY"]
secrets = ["CLOUDFLARE_ROOT_KEY"]
11 changes: 11 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"packages": ["rustup@latest", "libiconv@latest"],
"shell": {
"init_hook": ["rustup default stable", "cargo fetch"],
"scripts": {
"test": "cargo test -- --show-output",
"start": "cargo run",
"build-docs": "cargo doc"
}
}
}
82 changes: 82 additions & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"lockfile_version": "1",
"packages": {
"libiconv@latest": {
"last_modified": "2024-03-22T11:26:23Z",
"resolved": "github:NixOS/nixpkgs/a3ed7406349a9335cb4c2a71369b697cecd9d351#libiconv",
"source": "devbox-search",
"version": "2.38",
"systems": {
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/vzchfq6fvnvp6qipm393ymjbgxjjsysi-glibc-iconv-2.38",
"default": true
}
],
"store_path": "/nix/store/vzchfq6fvnvp6qipm393ymjbgxjjsysi-glibc-iconv-2.38"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/qkg9zz9rpd6spva392vxl9i7i7yq98hn-glibc-iconv-2.38",
"default": true
}
],
"store_path": "/nix/store/qkg9zz9rpd6spva392vxl9i7i7yq98hn-glibc-iconv-2.38"
}
}
},
"rustup@latest": {
"last_modified": "2024-03-22T11:26:23Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/a3ed7406349a9335cb4c2a71369b697cecd9d351#rustup",
"source": "devbox-search",
"version": "1.26.0",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/4h4wdqlcn4zjxkkyd6s97pg1xfajmd9v-rustup-1.26.0",
"default": true
}
],
"store_path": "/nix/store/4h4wdqlcn4zjxkkyd6s97pg1xfajmd9v-rustup-1.26.0"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/aqjaj4clf99y11mpp9yhbp1c364gkx4h-rustup-1.26.0",
"default": true
}
],
"store_path": "/nix/store/aqjaj4clf99y11mpp9yhbp1c364gkx4h-rustup-1.26.0"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/wn6ka9g6nzgd1wfmyy5jfb9m89b9mzzc-rustup-1.26.0",
"default": true
}
],
"store_path": "/nix/store/wn6ka9g6nzgd1wfmyy5jfb9m89b9mzzc-rustup-1.26.0"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/d2kbjhk0l81i1yflqfbkxqjfgq0xx1qz-rustup-1.26.0",
"default": true
}
],
"store_path": "/nix/store/d2kbjhk0l81i1yflqfbkxqjfgq0xx1qz-rustup-1.26.0"
}
}
}
}
}

0 comments on commit aacf0b4

Please sign in to comment.