Skip to content

Commit 3f1fa02

Browse files
authored
Merge pull request #428 from TypedDevs/feat/install-with-only-version-arg
Make installer args more flexible
2 parents 30dbcd7 + 0183b77 commit 3f1fa02

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Support placeholder `::ignore::` in snapshots
1111
- Add project overview docs
1212
- Improve clock performance
13+
- Make install.sh args more flexible
1314

1415
## [0.20.0](https://github.com/TypedDevs/bashunit/compare/0.19.1...0.20.0) - 2025-06-01
1516

docs/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ https://github.com/TypedDevs/bashunit/releases/download/{{ pkg.version }}/checks
3131

3232
#### Define custom tag and folder
3333

34-
The installation script can receive two optional arguments:
34+
The installation script can receive arguments (in any order):
3535

3636
```bash
3737
curl -s https://bashunit.typeddevs.com/install.sh | bash -s [dir] [version]
3838
```
3939
- `[dir]`: the destiny directory to save the executable bashunit; `lib` by default
40-
- `[version]`: the [release](https://github.com/TypedDevs/bashunit/releases) to download, for instance `{{ pkg.version }}`; `latest` by default
40+
- `[version]`: the [release](https://github.com/TypedDevs/bashunit/releases) to download, for instance `{{ pkg.version }}`; `latest` by default.
4141

4242
::: tip
4343
You can use `beta` as `[version]` to get the next non-stable preview release.

install.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,33 @@ function install() {
6363
######### MAIN ##########
6464
#########################
6565

66-
DIR=${1-lib}
67-
VERSION=${2-latest}
66+
# Defaults
67+
DIR="lib"
68+
VERSION="latest"
69+
70+
function is_version() {
71+
[[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ || "$1" == "latest" || "$1" == "beta" ]]
72+
}
73+
74+
# Parse arguments flexibly
75+
if [[ $# -eq 1 ]]; then
76+
if is_version "$1"; then
77+
VERSION="$1"
78+
else
79+
DIR="$1"
80+
fi
81+
elif [[ $# -eq 2 ]]; then
82+
if is_version "$1"; then
83+
VERSION="$1"
84+
DIR="$2"
85+
elif is_version "$2"; then
86+
DIR="$1"
87+
VERSION="$2"
88+
else
89+
echo "Invalid arguments. Expected version or directory." >&2
90+
exit 1
91+
fi
92+
fi
6893

6994
BASHUNIT_GIT_REPO="https://github.com/TypedDevs/bashunit"
7095
if is_git_installed; then

tests/acceptance/install_test.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@ function test_install_downloads_the_given_version() {
8484
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"
8585
}
8686

87+
function test_install_downloads_the_given_version_without_dir() {
88+
if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then
89+
skip "no internet connection" && return
90+
fi
91+
92+
local installed_bashunit="./lib/bashunit"
93+
local output
94+
output="$(./install.sh 0.19.0)"
95+
96+
assert_same \
97+
"$(printf "%s\n" \
98+
"> Downloading a concrete version: '0.19.0'" \
99+
"> bashunit has been installed in the 'lib' folder" \
100+
)" \
101+
"$output"
102+
103+
assert_file_exists "$installed_bashunit"
104+
105+
assert_same \
106+
"$(printf "\e[1m\e[32mbashunit\e[0m - 0.19.0")" \
107+
"$("$installed_bashunit" --env "$TEST_ENV_FILE" --version)"
108+
}
109+
87110
function test_install_downloads_the_non_stable_beta_version() {
88111
if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then
89112
skip "no internet connection" && return

0 commit comments

Comments
 (0)