Skip to content

Commit

Permalink
Merge pull request #2 from gliderlabs/master
Browse files Browse the repository at this point in the history
0.0.3 release
  • Loading branch information
andyshinn committed Feb 9, 2015
2 parents 0a0ef2c + 5d02136 commit 080c84f
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 370 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
example/.gun
example/.gun
bindata.go
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Change Log
All notable changes to this project will be documented in this file.

## [Unreleased][unreleased]
### Fixed

### Added

### Removed

### Changed

## [0.0.3] - 2015-02-09
### Fixed
- Fixed profile loading logic

### Added
- Added basic colored output helpers
- Added `fn-source` function

### Removed
- Dropped bindata.go from versioned source

### Changed
- Changed `env-export` to `env-import`, now allows default value
- Checksum checking is skipped if index provides none
- `show-env` (`env` subcommand) output is better aligned

## [0.0.2] - 2015-02-04
### Fixed
- Fixed profiles not loading

[unreleased]: https://github.com/gliderlabs/glidergun/compare/v0.0.3...HEAD
[0.0.3]: https://github.com/gliderlabs/glidergun/compare/v0.0.1...v0.0.3
[0.0.2]: https://github.com/gliderlabs/glidergun/compare/v0.0.1...v0.0.2
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NAME=glidergun
BINARYNAME=gun
ARCH=$(shell uname -m)
VERSION=0.0.2
VERSION=0.0.3

build:
go-bindata include
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

## Install

$ curl -sL https://github.com/gliderlabs/glidergun/releases/download/v0.0.1/glidergun_0.0.1_$(uname -s)_$(uname -m).tgz | tar -zxv -C /usr/local/bin
$ curl dl.gliderlabs.com/glidergun/latest/$(uname -sm|tr \ _).tgz \
| tar -zxC /usr/local/bin
334 changes: 0 additions & 334 deletions bindata.go

This file was deleted.

4 changes: 2 additions & 2 deletions example/cmds/aws.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

init() {
env-export AWS_ACCESS_KEY_ID
env-export AWS_SECRET_ACCESS_KEY
env-import AWS_ACCESS_KEY_ID
env-import AWS_SECRET_ACCESS_KEY
deps-require aws
}

Expand Down
1 change: 1 addition & 0 deletions glidergun.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ func main() {
"include/env.bash",
"include/gun.bash",
"include/deps.bash",
"include/color.bash",
}, Asset, true)
}
36 changes: 36 additions & 0 deletions include/color.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

declare -A color_table=(
["red"]='\033[00;31m'
["green"]='\033[00;32m'
["yellow"]='\033[00;33m'
["blue"]='\033[00;34m'
["purple"]='\033[00;35m'
["cyan"]="\033[00;36m"
["white"]='\033[00;37m'
["red-bright"]='\033[01;31m'
["green-bright"]='\033[01;32m'
["yellow-bright"]='\033[01;33m'
["blue-bright"]='\033[01;34m'
["purple-bright"]='\033[01;35m'
["cyan-bright"]='\033[01;36m'
["white-bright"]='\033[01;37m'
)

color-init() {
for color in "${!color_table[@]}"; do
eval "$color() { color-cat $color; }"
done
}

color-cat() {
declare color="$1"
while read -r; do
printf "${color_table[$color]}%s\033[0m\n" "$REPLY"
done
}

color-cycle() {
colors=(${!color_table[@]})
index="$((($BASHPID%${#color_table[@]})))"
color-cat "${colors[$index]}"
}
12 changes: 7 additions & 5 deletions include/deps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ deps-dir() {
deps-require() {
declare name="$1" version="${2:-latest}"
deps-check "$name" "$version" && return
echo "* Dependency required, installing $name $version ..."
echo "* Dependency required, installing $name $version ..." | yellow
deps-install "$name" "$version"
}

Expand All @@ -29,17 +29,19 @@ deps-install() {
index=$(curl -s "$DEPS_REPO/$name")
tag="$(uname -s)$(uname -m | grep -s 64 > /dev/null && echo amd64 || echo 386)"
if ! dep="$(echo "$index" | grep -i -e "^$version $tag " -e "^$version * ")"; then
echo "!! Dependency not in index: $name $version"
echo "!! Dependency not in index: $name $version" | red
exit 2
fi
IFS=' ' read v t url checksum <<< "$dep"
tmpdir="$(deps-dir)/tmp"
mkdir -p "$tmpdir"
tmpfile="${tmpdir:?}/$name"
curl -s $url > "$tmpfile"
if ! [[ "$(cat "$tmpfile" | md5)" = "$checksum" ]]; then
echo "!! Dependency checksum failed: $name $version $checksum"
exit 2
if [[ "$checksum" ]]; then
if ! [[ "$(cat "$tmpfile" | md5)" = "$checksum" ]]; then
echo "!! Dependency checksum failed: $name $version $checksum" | red
exit 2
fi
fi
cd "$tmpdir"
filename="$(basename "$url")"
Expand Down
20 changes: 17 additions & 3 deletions include/env.bash
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@

declare -a _env

env-export() {
declare var="$1"
env-import() {
declare var="$1" default="$2"
if [[ -z "${!var+x}" ]]; then
if [[ -z "${2+x}" ]]; then
echo "!! Imported variable $var must be set in profile or environment." | red
exit 2
else
export $var="$default"
fi
fi
_env+=($var)
}

env-show() {
local longest=0
for var in "${_env[@]}"; do
echo "$var=${!var}"
if [[ "${#var}" -gt "$longest" ]]; then
longest="${#var}"
fi
done
for var in "${_env[@]}"; do
printf "%-${longest}s = %s\n" "$var" "${!var}"
done
}
8 changes: 7 additions & 1 deletion include/fn.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ fn-info() {
echo " $(fn-desc $fn)"
echo
if [[ "$showsource" ]]; then
type $fn | tail -n +2
type $fn
echo
fi
}

fn-source() {
declare desc="Shows function source"
declare fn="$1"
declare -f $fn | tail -n +2
}

fn-call() {
declare desc="Run arbitrary function"
declare fn="$1"; shift
Expand Down
43 changes: 21 additions & 22 deletions include/gun.bash
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

declare GUN_MODULE_DIR="${GUN_MODULE_DIR:-cmds}"
declare GUN_ROOT

gun-init() {
declare desc="Initialize a glidergun project directory"
mkdir .gun
if [[ -f .gitignore ]]; then
if ! grep '^.gun$' .gitignore > /dev/null; then
Expand All @@ -12,6 +12,7 @@ gun-init() {
}

gun-version() {
declare desc="Display version of glidergun"
echo "glidergun $GUN_VERSION"
}

Expand All @@ -26,39 +27,37 @@ gun-find-root() {
fi
}

gun-load-profile() {
declare profile="$1"
if [[ -f ".gun_$profile" ]]; then
source ".gun_$profile"
return
else
if [[ "$GUN_DEFAULT_PROFILE" && -f ".gun_$GUN_DEFAULT_PROFILE" ]]; then
source ".gun_$GUN_DEFAULT_PROFILE"
echo "* Using default profile $GUN_DEFAULT_PROFILE"
return
fi
fi
return 1
}

main() {
set -eo pipefail; [[ "$TRACE" ]] && set -x
gun-find-root
color-init
gun-find-root

if [[ "$GUN_ROOT" ]]; then
deps-init
if gun-load-profile "$1"; then
if [[ -f ".gun_$1" ]]; then
source ".gun_$1"
GUN_PROFILE="$1"
shift
elif [[ "$GUN_DEFAULT_PROFILE" && -f ".gun_$GUN_DEFAULT_PROFILE" ]]; then
source ".gun_$GUN_DEFAULT_PROFILE"
echo "* Using default profile $GUN_DEFAULT_PROFILE" | yellow
GUN_PROFILE="$GUN_DEFAULT_PROFILE"
fi
if [[ -d "$GUN_MODULE_DIR" ]]; then
module-load-dir "$GUN_MODULE_DIR"
if [[ "$GUN_PROFILE" ]]; then
if [[ -d "$GUN_MODULE_DIR" ]]; then
module-load-dir "$GUN_MODULE_DIR"
fi
cmd-export env-show env
cmd-export fn-call fn
else
if [[ "$1" != "init" && "$1" != "version" && "$1" != "help" ]]; then
echo "* Unable to load profile $1" | yellow
fi
fi
fi

cmd-export gun-init init
cmd-export gun-version version
cmd-export env-show env
cmd-export fn-call fn

cmd-ns "" "$@"
}

0 comments on commit 080c84f

Please sign in to comment.