Skip to content

Commit

Permalink
Add installing software from a Brewfile
Browse files Browse the repository at this point in the history
  • Loading branch information
norm committed Sep 12, 2021
1 parent 9161557 commit 21b4534
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
Brewfile.lock.json
tests/alternate-brewfile.lock.json
5 changes: 5 additions & 0 deletions documentation/kitfile.markdown
Expand Up @@ -73,3 +73,8 @@ Available commands are:
Sets the default directory for `clone` commands to _DIRECTORY_;
if _DIRECTORY_ is not specified, the original value of
$HOME/Code is restored.

* brewfile [_FILE_]

Runs `brew bundle` with _FILE_. If _FILE_ is not specified, it will
use "`Brewfile`".
24 changes: 22 additions & 2 deletions kitout.sh
Expand Up @@ -98,7 +98,15 @@ function epad {
}

function process_kitfile {
while read command argument; do
# cache the kitfile in memory, rather than relying on streaming
# from disk; in some cases (brew bundle...) that gets interrupted
local -a kitfile
while IFS= read -r line; do
kitfile+=("$line")
done < "$1"

for line in "${kitfile[@]}"; do
read command argument <<<"$line"
case "$command" in
\#|'') : ;;
echo) output "$argument" ;;
Expand All @@ -107,10 +115,11 @@ function process_kitfile {

repodir) set_repodir "$argument" ;;
clone) clone_repository $argument ;;
brewfile) brewfile "$argument" ;;

*) error "Unknown command: '$command'" ;;
esac
done < <(cat "$1")
done
}

function set_repodir {
Expand Down Expand Up @@ -194,4 +203,15 @@ function clone_repository {
fi
}

function brewfile {
local file="${1:-Brewfile}"

if [ -f "$file" ]; then
action "installing from $file"
HOMEBREW_NO_COLOR=1 brew bundle --file "$file"
else
error "brewfile '$file' does not exist"
fi
}

main "$@"
6 changes: 6 additions & 0 deletions tests/alternate-brewfile
@@ -0,0 +1,6 @@
# already installed
brew 'bats-core'

# to be installed (obviously this could break if gimme
# is ever actually deliberately installed)
brew 'gimme'
24 changes: 24 additions & 0 deletions tests/brewfile.bats
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

bold=$'\e'[1m
magenta=$'\e'[35m
reset=$'\e'[0m

@test brewfile {
run ./kitout.sh tests/brewfile.kitfile
echo "$output"
[ "${lines[1]}" == "Using bats-core" ]
[ "${lines[4]}" == "Using bats-core" ]
[ "${lines[5]}" == "Installing gimme" ]
[ "${lines[7]}" == "${bold}${magenta}*** brewfile 'i-dont-exist' does not exist${reset}" ]
[ $status -eq 1 ]
}

function setup_file {
brew update
teardown
}

function teardown {
brew uninstall --force gimme
}
3 changes: 3 additions & 0 deletions tests/brewfile.kitfile
@@ -0,0 +1,3 @@
brewfile
brewfile tests/alternate-brewfile
brewfile i-dont-exist

0 comments on commit 21b4534

Please sign in to comment.