Skip to content

Commit

Permalink
Clean up internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Kelling committed Apr 29, 2014
1 parent cc93732 commit 060dc5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 58 deletions.
29 changes: 14 additions & 15 deletions src/ellipsis.sh
Expand Up @@ -24,13 +24,13 @@ ellipsis.list_packages() {
ellipsis.each() {
# execute command for ellipsis first
pkg.init $ELLIPSIS_PATH
pkg.run "$@"
$@
pkg.del

# loop over packages, excecuting command
for pkg in $(ellipsis.list_packages); do
pkg.init "$pkg"
pkg.run "$@"
$@
pkg.del
done
}
Expand Down Expand Up @@ -60,65 +60,65 @@ ellipsis.install() {
git.clone "$PKG_URL" "$PKG_PATH"

pkg.init "$PKG_PATH"
pkg.run pkg.install
pkg.run_hook install
pkg.del
}

# Uninstall package, using uninstall hook if one exists. If no hook is
# defined, all symlinked files in ELLIPSIS_HOME are removed and package is rm -rf'd.
ellipsis.uninstall() {
pkg.init "$1"
pkg.run pkg.uninstall
pkg.run_hook uninstall
pkg.del
}

# Unlink package, using unlink hooks, using unlink hook if one exists. If no
# hook is defined, all symlinked files in ELLIPSIS_HOME are removed.
ellipsis.unlink() {
pkg.init "$1"
pkg.run pkg.unlink
pkg.run_hook unlink
pkg.del
}

# List installed packages.
ellipsis.list() {
if utils.cmd_exists column; then
ellipsis.each pkg.list | column -t -s $'\t'
ellipsis.each pkg.run_hook list | column -t -s $'\t'
else
ellipsis.each pkg.list
ellipsis.each pkg.run_hook list
fi
}

# List(s) package git status.
ellipsis.status() {
if [ $# -eq 1 ]; then
pkg.init "$1"
pkg.run pkg.status
pkg.run_hook status
pkg.del
else
ellipsis.each pkg.status
ellipsis.each pkg.run_hook status
fi
}

# Updates package(s) with git pull.
ellipsis.pull() {
if [ $# -eq 1 ]; then
pkg.init "$1"
pkg.run pkg.pull
pkg.run_hook pull
pkg.del
else
ellipsis.each pkg.pull
ellipsis.each pkg.run_hook pull
fi
}

# Push updated package(s) with git push.
ellipsis.push() {
if [ $# -eq 1 ]; then
pkg.init "$1"
pkg.run pkg.push
pkg.run_hook push
pkg.del
else
ellipsis.each pkg.push
ellipsis.each pkg.run_hook push
fi
}

Expand Down Expand Up @@ -206,7 +206,7 @@ ellipsis.edit() {
ellipsis.symlinks() {
if [ $# -eq 1 ]; then
pkg.init "$1"
pkg.run pkg.symlinks
pkg.run_hook symlinks
pkg.del
else
if utils.cmd_exists column; then
Expand All @@ -228,4 +228,3 @@ ellipsis.broken() {
ellipsis.clean() {
find -L $ELLIPSIS_HOME -maxdepth 1 -type l| xargs rm
}

54 changes: 11 additions & 43 deletions src/pkg.sh
Expand Up @@ -66,64 +66,32 @@ pkg.symlinks_mappings() {
done
}

# Run hook or command inside PKG_PATH.
# Run command inside PKG_PATH.
pkg.run() {
local cwd="$(pwd)"

# change to package dir
cd "$PKG_PATH"

# run hook or command
case $1 in
pkg.*)
pkg.run_hook $1
;;
*)
$1
;;
esac
# run command
$@

# return after running command
cd "$cwd"
}

# run hook if it's defined, otherwise use default implementation
pkg.run_hook() {
if ! utils.cmd_exists hooks.$1; then
log.error "Unknown hook!"
exit 1
fi

# Run packages's hook.
if utils.cmd_exists $1; then
$1
if utils.cmd_exists pkg.$1; then
run pkg.$1
else
# Run default hook.
case $1 in
pkg.install)
pkg.hooks.install
;;
pkg.unlink)
pkg.hooks.unlink
;;
pkg.uninstall)
pkg.hooks.uninstall
;;
pkg.symlinks)
pkg.hooks.symlinks
;;
pkg.pull)
pkg.hooks.pull
;;
pkg.push)
pkg.hooks.push
;;
pkg.list)
pkg.hooks.list
;;
pkg.status)
pkg.hooks.status
;;
*)
echo Unknown hook!
exit 1
;;
esac
run hooks.$1
fi
}

Expand Down

0 comments on commit 060dc5f

Please sign in to comment.