devscript: all large scripts use die/warn idiom

This commit is contained in:
Roland Walker
2014-01-31 12:33:29 -05:00
parent 572eea7cbe
commit 96eb76f676
4 changed files with 55 additions and 22 deletions
+17 -8
View File
@@ -7,13 +7,25 @@ set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions
warn () {
local message="$@"
if ! [[ $message =~ "\n"$ ]]; then
message="${message}\n"
fi
printf "$message" 1>&2
}
die () {
warn "$@"
exit 1
}
cd_to_project_root () {
local script_dir="$(/usr/bin/dirname $0)"
cd "$script_dir"
local git_root="$(git rev-parse --show-toplevel)"
if [[ -z "$git_root" ]]; then
printf "Could not find git project root"
exit 1
die "Could not find git project root"
fi
cd "$git_root"
}
@@ -22,8 +34,7 @@ cd_to_version_dir () {
local cellar_dir="$1"
local version_dir="$2"
if [[ -z "$version_dir" ]]; then
printf "Can't get version dir under $cellar_dir/\n"
exit 1
die "Can't get version dir under $cellar_dir/"
fi
cd "$cellar_dir/$version_dir"
}
@@ -57,15 +68,13 @@ _develop_brew_cask () {
# sanity check
if [[ "$(/usr/bin/stat -L -f '%i' "$tap_dir")" -eq "$(/usr/bin/stat -L -f '%i' "$git_root")" ]]; then
printf "\nERROR: run this script in your private repo, not inside Homebrew.\n"
exit 1
die "\nERROR: run this script in your private repo, not inside Homebrew."
fi
# action
cd_to_version_dir "$cellar_dir" "$version_dir"
if [[ -e "production_rubylib" ]]; then
printf "brew-cask is already set up for development\n"
exit 1
die "brew-cask is already set up for development"
else
create_dev_links "$git_root" "$tap_dir"
printf "brew-cask is now in development mode\n"
+5 -1
View File
@@ -11,12 +11,16 @@ opt_next=''
opt_latest=''
opt_verbose=''
die () {
warn () {
local message="$@"
if ! [[ $message =~ "\n"$ ]]; then
message="${message}\n"
fi
printf "$message" 1>&2
}
die () {
warn "$@"
exit 1
}
+17 -8
View File
@@ -7,13 +7,25 @@ set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions
warn () {
local message="$@"
if ! [[ $message =~ "\n"$ ]]; then
message="${message}\n"
fi
printf "$message" 1>&2
}
die () {
warn "$@"
exit 1
}
cd_to_project_root () {
local script_dir="$(/usr/bin/dirname $0)"
cd "$script_dir"
local git_root="$(git rev-parse --show-toplevel)"
if [[ -z "$git_root" ]]; then
printf "Could not find git project root"
exit 1
die "Could not find git project root"
fi
cd "$git_root"
}
@@ -22,8 +34,7 @@ cd_to_version_dir () {
local cellar_dir="$1"
local version_dir="$2"
if [[ -z "$version_dir" ]]; then
printf "Can't get version dir under $cellar_dir/\n"
exit 1
die "Can't get version dir under $cellar_dir/"
fi
cd "$cellar_dir/$version_dir"
}
@@ -54,8 +65,7 @@ _production_brew_cask () {
# sanity check
if [[ "$(/usr/bin/stat -L -f '%i' "$tap_dir")" -eq "$(/usr/bin/stat -L -f '%i' "$git_root")" ]]; then
printf "\nERROR: run this script in your private repo, not inside Homebrew.\n"
exit 1
die "\nERROR: run this script in your private repo, not inside Homebrew."
fi
# action
@@ -65,8 +75,7 @@ _production_brew_cask () {
printf "brew-cask is now in production mode\n"
printf "It is safe to run 'brew update'\n"
else
printf "brew-cask is already set up for production\n"
exit 1
die "brew-cask is already set up for production"
fi
}
+16 -5
View File
@@ -9,13 +9,25 @@ set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions
warn () {
local message="$@"
if ! [[ $message =~ "\n"$ ]]; then
message="${message}\n"
fi
printf "$message" 1>&2
}
die () {
warn "$@"
exit 1
}
cd_to_project_root () {
local script_dir="$(/usr/bin/dirname $0)"
cd "$script_dir"
local git_root="$(git rev-parse --show-toplevel)"
if [[ -z "$git_root" ]]; then
printf "Could not find git project root"
exit 1
die "Could not find git project root"
fi
cd "$git_root"
}
@@ -27,14 +39,13 @@ warn_if_off_branch () {
wanted_branch="$1"
fi
if ! [[ "$branch" = "$wanted_branch" ]]; then
printf "\nWARNING: you are running from branch '$branch', not '$wanted_branch'\n\n"
warn "\nWARNING: you are running from branch '$branch', not '$wanted_branch'\n\n"
fi
}
verify_git_object () {
if ! git rev-parse --verify "$1" > /dev/null 2>/dev/null; then
printf "\nERROR: No such commit object: $1\n\n"
exit 1
die "\nERROR: No such commit object: $1"
fi
}