Skip to content

Commit 5fd72dd

Browse files
author
Konstantin Gredeskoul
committed
Adding bin/setup help + updating README.
* also adding bin/setup no-git-hook * also adding bin/setup help
1 parent eeaa064 commit 5fd72dd

2 files changed

Lines changed: 103 additions & 13 deletions

File tree

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,51 @@ To get the initial stuff setup required by this repo, please run the script:
436436
bin/setup
437437
```
438438

439-
Whenever you'll commit something, a pre-commit hook will run as well.
439+
This script does a couple of very useful things, including setting up a git commit
440+
hook that performs rubocop fixes and buildifier fixes of the Bazel build files.
441+
442+
You can run partial setup comamnds like so:
443+
444+
```bash
445+
❯ bin/setup -h
446+
447+
USAGE:
448+
bin/setup [ gems | git-hook | help | install | main | no-git-hook ]
449+
450+
DESCRIPTION:
451+
Runs full setup without any arguments.
452+
453+
Accepts one argument — one of the actions that typically run
454+
as part of setup.
455+
456+
For instance, to perform full setup:
457+
458+
bin/setup
459+
460+
Or, to run only one of the sub-functions (actions), pass
461+
it as an argument:
462+
463+
bin/setup help
464+
bin/setup no-git-hook
465+
466+
etc.
467+
```
468+
469+
Whenever you'll commit something, a pre-commit hook will run as well. If it
470+
finds anything that needs fixing, it will attempt to fix it. If the resulting
471+
git state is different than before the commit, the commit is aborted and the user
472+
should add any auto-fixed modifications to the list of staged files for commit.
440473

441474
### Running Tests
442475

443-
We have a handy script you can use to run all tests:
476+
We have a pretty useful script you can use to run all tests in the repo that run on CI:
444477

445478
```bash
446479
bin/ci
447480
```
448481

482+
On a MacBook Pro it takes about 3 minutes to run.
483+
449484
## Copyright
450485

451486
© 2018-2019 Yuki Yugui Sonoda & BazelRuby Authors

bin/setup

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,68 @@
11
#!/usr/bin/env bash
2-
2+
#
3+
#
4+
#
35
set -e
46
# shellcheck disable=SC1091
57
source "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+
741
setup::gems() {
842
for gem in rubocop relaxed-rubocop rubocop-performance; do
943
lib::gem::install ${gem}
1044
done
1145
}
1246

13-
setup::git() {
14-
inf 'Installing git pre-commit hook'
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() {
1558
set -e
16-
[[ -L .git/hooks/pre-commit ]] || run "cd .git/hooks && ln -nfs ../../bin/pre-commit pre-commit"
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
1765
set +e
18-
ok:
1966
}
2067

2168
setup::install() {
@@ -36,27 +83,35 @@ setup::install() {
3683
/usr/bin/env bash bin/show-env || true
3784
fi
3885
else
39-
error "Operating system $(uname -s) is not currently supported." >&2
86+
error "Operating system ${os} is not currently supported." >&2
4087
fi
4188
echo
4289
return 0
4390
}
4491

4592
setup::main() {
4693
local action="$1"
94+
[[ "${action}" == "-h" || ${action} == "--help" ]] && action="help"
4795
local func="setup::${action}"
4896

49-
if lib::util::is-a-function "${func}"; then
50-
h2 "Executing partial setup for action ${bldylw}${action}"
51-
shift
52-
${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
53106
else
54107
set +e
55108
h2 "Installing required development dependencies for working with rules_ruby and Bazel."
56109
setup::gems
57-
[[ -z ${CI} ]] && setup::git
110+
[[ -z ${CI} ]] && setup::git-hook
58111
setup::install "$@"
59112
fi
60113
}
61114

62115
setup::main "$@"
116+
117+

0 commit comments

Comments
 (0)