Last active
August 29, 2015 14:07
-
-
Save hiracy/2ae3f562d31569516da5 to your computer and use it in GitHub Desktop.
update_serverspec_recipes_1.x.x_to_2.x.x.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TEST=0 | |
SPEC_PATH="." | |
COND_EXIT_STATUS="return_exit_status" | |
COND_STDOUT="return_stdout" | |
COND_STDERR="return_stderr" | |
usage () { | |
echo "Usage: `basename $0` [options]" | |
echo "[-h|--help ] :show help" | |
echo "[-t|--test ] :show file only" | |
echo "[-s|--specpath ] :replace spec path" | |
exit 0 | |
} | |
parse_opts () { | |
while [ $# -ne 0 ] | |
do | |
case "$1" in | |
-h|--help) usage;; | |
-t|--test ) TEST=1; shift;; | |
-s|--specpath) [ "$2" == "" ] && { usage; exit 1; }; SPEC_PATH=$2; shift 2 ;; | |
--) shift; break ;; | |
*) usage;; | |
esac | |
done | |
} | |
[ $# -eq 0 ] && { usage;exit 0; } | |
parse_opts $@ | |
[ "$SPEC_PATH" == "" ] && { usage; exit 1; } | |
[ "$SPEC_PATH" == "/" ] && { echo "/ is not allowed.";exit 1; } | |
if [ $TEST -eq 1 ];then | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -e ${COND_EXIT_STATUS} -e ${COND_STDOUT} -e ${COND_STDERR} | |
exit 0 | |
fi | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_EXIT_STATUS} | xargs sed -i -e "s/it { should return_exit_status/its(:exit_status)\{ should eq/g" | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_EXIT_STATUS} | xargs sed -i -e "s/it { should_not return_exit_status/its(:exit_status) { should_not eq/g" | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_STDOUT} | xargs sed -i -e "s/it { should return_stdout/its(:stdout) { should match/g" | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_STDOUT} | xargs sed -i -e "s/it { should_not return_stdout/its(:stdout) { should_not match/g" | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_STDERR} | xargs sed -i -e "s/it { should return_stderr/its(:stderr) { shouldmatch/g" | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_STDERR} | xargs sed -i -e "s/it { should_not return_stderr/its(:stderr) { should_not match/g" | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_EXIT_STATUS} | xargs sed -i -e "s/return_exit_status/eq/g" | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_STDOUT} | xargs sed -i -e "s/return_stdout/match/g" | |
find ${SPEC_PATH} -name '*.rb' | xargs grep -l ${COND_STDERR} | xargs sed -i -e "s/return_stderr/match/g" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment