Skip to content

Instantly share code, notes, and snippets.

@abachman
Created March 16, 2009 16:19
Show Gist options
  • Save abachman/79949 to your computer and use it in GitHub Desktop.
Save abachman/79949 to your computer and use it in GitHub Desktop.
multi-env rake command for rails projects
#!/bin/bash
#
# For example, you're deep in prototyping mode, and want to keep your test
# and development environments in sync. Don't keep typing:
# rake RAILS_ENV=test db:migrate && rake RAILS_ENV=development db:migrate
# instead:
# rakes -dt db:migrate
#
# don't repeat yourself.
while getopts 'dtsp' OPTION
do
case $OPTION in
d) denv="development"
;;
t) tenv="test"
;;
s) senv="staging"
;;
p) penv="production"
;;
h|?)
printf "Run rake on multiple RAILS_ENVs.\n\n" >&2
printf "Usage: %s [-dtsp] tasks\n" $(basename $0) >&2
printf "\t-h\tShow this help screen and exit\n" >&2
printf "\t-d\tdevelopment\n" >&2
printf "\t-t\ttest\n" >&2
printf "\t-s\tstaging\n" >&2
printf "\t-p\tproduction\n" >&2
exit 2
;;
esac
done
shift $(($OPTIND - 1))
for renv in "$denv" "$tenv" "$senv" "$penv"; do
if [ -n "$renv" ]; then
echo "Running rake tasks [$@] on $renv"
rake RAILS_ENV=$renv $@
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment