diff --git a/developer/bin/develop_brew_cask b/developer/bin/develop_brew_cask index 577a1178d5..be770fe387 100755 --- a/developer/bin/develop_brew_cask +++ b/developer/bin/develop_brew_cask @@ -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" diff --git a/developer/bin/get_release_tag b/developer/bin/get_release_tag index 75db48b175..dc03756b41 100755 --- a/developer/bin/get_release_tag +++ b/developer/bin/get_release_tag @@ -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 } diff --git a/developer/bin/production_brew_cask b/developer/bin/production_brew_cask index 60d722a1ae..12e16e0dc9 100755 --- a/developer/bin/production_brew_cask +++ b/developer/bin/production_brew_cask @@ -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 } diff --git a/developer/bin/project_stats b/developer/bin/project_stats index 767e8e0d13..5366422895 100755 --- a/developer/bin/project_stats +++ b/developer/bin/project_stats @@ -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 }