Skip to content

Commit

Permalink
abort with informative message if Bash version is inadequate
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Dec 12, 2023
1 parent 2de3c80 commit 10b01b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ Several things will happen if one elects to continue:
git push --atomic origin refs/heads/master refs/tags/v0.6.1
env VERSION=0.6.1 PREVIOUS_VERSION=0.6.0 bash -c 'npm publish'

_**macOS Mojave**, released in 2018, provides a version of Bash from 2007.
xyz uses a feature added in Bash 4, released in 2009. macOS users should run
`brew install bash` to install a compatible Bash version._
> [!IMPORTANT]
>
> **macOS Mojave**, released in 2018, provides a version of Bash from 2007.
> xyz uses a feature added in Bash 4, released in 2009. macOS users should run
> `brew install bash` to install a compatible Bash version.
## Usage

Expand Down
25 changes: 19 additions & 6 deletions xyz
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Options:
"

abort() {
printf '%s\n' "$1" >&2
printf '%s\n' "$@" >&2
exit 1
}

Expand Down Expand Up @@ -127,6 +127,24 @@ inc() {
printf %s "$version"
}

if type tput &>/dev/null ; then
bold=$(tput bold)
smul=$(tput smul)
rmul=$(tput rmul)
reset=$(tput sgr0)
fi

check_bash_version() {
if (( BASH_VERSINFO[0] < 4 )) ; then
local xyz
xyz="$(IFS=.; echo "${BASH_VERSINFO[*]:0:3}")"
abort \
"Inadequate Bash version: ${bold}${xyz}${reset} < ${bold}4.0.0${reset}" \
"${smul}https://github.com/davidchambers/xyz/issues/51${rmul}"
fi
}
check_bash_version

declare -A options=(
[branch]=master
[dry-run]=false
Expand Down Expand Up @@ -201,11 +219,6 @@ next_version=$(inc "${options[prerelease-label]}" \
message="${options[message]//X.Y.Z/$next_version}"
tag="${options[tag]//X.Y.Z/$next_version}"

if type tput &>/dev/null ; then
bold=$(tput bold)
reset=$(tput sgr0)
fi

printf "Current version is %s. Press [enter] to publish %s." \
"${bold}${version}${reset}" \
"${bold}${name}@${next_version}${reset}"
Expand Down

0 comments on commit 10b01b9

Please sign in to comment.