11#! /usr/bin/env bash
2-
2+ #
3+ #
4+ #
35set -e
46# shellcheck disable=SC1091
57source " bin/deps"
68
9+ __setup::actions () {
10+ local sep=" ${1:- ' , ' } "
11+ printf " ${bldylw} $( lib::array::join " ${sep} " $( lib::util::functions-matching setup::) ) "
12+ }
13+
14+ setup::help () {
15+ printf "
16+ ${bldpur} USAGE:${clr}
17+ bin/setup [ $( __setup::actions " | " ) ${clr} ]
18+
19+ ${bldpur} DESCRIPTION:${clr}
20+ Runs full setup without any arguments.
21+
22+ Accepts one argument — one of the actions that typically run
23+ as part of setup.
24+
25+ For instance, to perform full setup:
26+
27+ ${bldylw} bin/setup${clr}
28+
29+ Or, to run only one of the sub-functions (actions), pass
30+ it as an argument:
31+
32+ ${bldylw} bin/setup help${clr}
33+ ${bldylw} bin/setup no-git-hook${clr}
34+
35+ etc.
36+ "
37+ }
38+
39+
40+
741setup::gems () {
842 for gem in rubocop relaxed-rubocop rubocop-performance; do
943 lib::gem::install ${gem}
1044 done
1145}
1246
13- setup::git () {
14- [[ -L .git/hooks/pre-commit ]] || run " ln -nfs bin/pre-commit .git/hooks/pre-commit"
47+ setup::no-git-hook () {
48+ set -e
49+ [[ -L .git/hooks/pre-commit ]] && {
50+ info ' Removing git commit hook...'
51+ run " rm -f .git/hooks/pre-commit"
52+ echo
53+ }
54+ set +e
55+ }
56+
57+ setup::git-hook () {
58+ set -e
59+ if [[ ! -L .git/hooks/pre-commit ]]; then
60+ info ' Installing git pre-commit hook'
61+ run " cd .git/hooks && ln -nfs ../../bin/pre-commit pre-commit && cd -"
62+ else
63+ info: " git pre-commit hook is already installed."
64+ fi
65+ set +e
1566}
1667
1768setup::install () {
@@ -32,27 +83,35 @@ setup::install() {
3283 /usr/bin/env bash bin/show-env || true
3384 fi
3485 else
35- error " Operating system $( uname -s ) is not currently supported." >&2
86+ error " Operating system ${os} is not currently supported." >&2
3687 fi
3788 echo
3889 return 0
3990}
4091
4192setup::main () {
4293 local action=" $1 "
94+ [[ " ${action} " == " -h" || ${action} == " --help" ]] && action=" help"
4395 local func=" setup::${action} "
4496
45- if lib::util::is-a-function " ${func} " ; then
46- h2 " Executing partial setup for action ${bldylw}${action} "
47- shift
48- ${func} " $@ "
97+ if [[ -n ${action} ]] ; then
98+ if lib::util::is-a-function " ${func} " ; then
99+ [[ ${action} != " help" ]] && h2 " Executing partial setup for action ${bldylw}${action} "
100+ shift
101+ ${func} " $@ "
102+ else
103+ h1 " Invalid action provided." " Valid actions are: $( __setup::actions) "
104+ exit 1
105+ fi
49106 else
50107 set +e
51108 h2 " Installing required development dependencies for working with rules_ruby and Bazel."
52109 setup::gems
53- [[ -z ${CI} ]] && setup::git
110+ [[ -z ${CI} ]] && setup::git-hook
54111 setup::install " $@ "
55112 fi
56113}
57114
58115setup::main " $@ "
116+
117+
0 commit comments