diff --git a/crates/pkgs/src/homebrew.rs b/crates/pkgs/src/homebrew.rs index a2354d9..fd96e69 100644 --- a/crates/pkgs/src/homebrew.rs +++ b/crates/pkgs/src/homebrew.rs @@ -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(()) } @@ -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("neovim@0.9.5"); + assert_eq!(command.get_args().len(), 2); + assert_eq!( + command.get_args().last().unwrap().to_string_lossy(), + "brew install neovim@0.9.5" + ); + } + + #[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" + ); + } +} diff --git a/demo/envhub.hcl b/demo/envhub.hcl index 2f4981d..ae91312 100644 --- a/demo/envhub.hcl +++ b/demo/envhub.hcl @@ -6,6 +6,12 @@ envs { EDITOR = "vim" } +homebrew { + packages = [ + "neovim --HEAD" + ] +} + file ".screenrc" { source = "dotfiles/.screenrc" } @@ -18,4 +24,4 @@ file ".gradle/gradle.properties" { content = "org.gradle.daemon=true" } -secrets = ["CLOUDFLARE_ROOT_KEY"] \ No newline at end of file +secrets = ["CLOUDFLARE_ROOT_KEY"] diff --git a/devbox.json b/devbox.json new file mode 100644 index 0000000..e0ed601 --- /dev/null +++ b/devbox.json @@ -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" + } + } +} diff --git a/devbox.lock b/devbox.lock new file mode 100644 index 0000000..853f76a --- /dev/null +++ b/devbox.lock @@ -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" + } + } + } + } +}