Skip to content

Commit 3815d7a

Browse files
IsaacGIsaac Good
andauthored
fetch-configlet: allow running from the bin directory (#284)
This commit improves the `fetch-configlet` script in two ways: 1. It allows `fetch-configlet` to be run from the `bin` directory itself, instead of requiring it to be run from the repo's root directory. 2. It will output an error if the repo root does not have a `bin` directory. Co-authored-by: Isaac Good <nuc-git@isaacgood.com>
1 parent 237e841 commit 3815d7a

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

scripts/fetch-configlet

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,26 @@ get_download_url() {
4545
cut -d'"' -f4
4646
}
4747

48-
download_url="$(get_download_url)"
49-
output_dir="bin"
50-
output_path="${output_dir}/latest-configlet.${ext}"
51-
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
52-
53-
case "${ext}" in
54-
*zip) unzip "${output_path}" -d "${output_dir}" ;;
55-
*) tar xzf "${output_path}" -C "${output_dir}" ;;
56-
esac
48+
main () {
49+
if [[ -d ./bin ]]; then
50+
output_dir="./bin"
51+
elif [[ $PWD = */bin ]]; then
52+
output_dir="$PWD"
53+
else
54+
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
55+
return 1
56+
fi
57+
58+
download_url="$(get_download_url)"
59+
output_path="${output_dir}/latest-configlet.${ext}"
60+
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
61+
62+
case "${ext}" in
63+
*zip) unzip "${output_path}" -d "${output_dir}" ;;
64+
*) tar xzf "${output_path}" -C "${output_dir}" ;;
65+
esac
66+
67+
rm -f "${output_path}"
68+
}
5769

58-
rm -f "${output_path}"
70+
main

0 commit comments

Comments
 (0)