-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcli.sh
67 lines (59 loc) · 2.31 KB
/
cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# rusty-hook
# version {{VERSION}}
# shellcheck disable=SC2170,SC1083
minimumMajorCliVersion={{MINIMUM_MAJOR}}
# shellcheck disable=SC2170,SC1083
minimumMinorCliVersion={{MINIMUM_MINOR}}
# shellcheck disable=SC2170,SC1083
minimumPatchCliVersion={{MINIMUM_PATCH}}
# shellcheck disable=SC2170,SC1083
allowPrereleaseCliVersion={{MINIMUM_ALLOW_PRE}}
# shellcheck disable=SC2170,SC1083
noConfigFileExitCode={{NO_CONFIG_FILE_EXIT_CODE}}
upgradeRustyHookCli() {
echo "[rusty-hook] Upgrading rusty-hook cli..."
echo "[rusty-hook] This may take a few seconds..."
cargo install --force rusty-hook >/dev/null 2>&1
}
installRustyHookCli() {
echo "[rusty-hook] Finalizing rusty-hook configuration..."
echo "[rusty-hook] This may take a few seconds..."
cargo install rusty-hook >/dev/null 2>&1
}
ensureMinimumRustyHookCliVersion() {
currentVersion=$(rusty-hook -v)
isGreaterThanEqualToMinimumVersion "${currentVersion}" ${minimumMajorCliVersion} ${minimumMinorCliVersion} ${minimumPatchCliVersion} ${allowPrereleaseCliVersion} >/dev/null 2>&1
versionCompliance=$?
if [ ${versionCompliance} -gt 0 ]; then
upgradeRustyHookCli || true
fi
}
handleRustyHookCliResult() {
rustyHookExitCode=${1}
hookName=${2}
# shellcheck disable=SC2086
if [ ${rustyHookExitCode} -eq 0 ]; then
exit 0
fi
# shellcheck disable=SC2086
if [ ${rustyHookExitCode} -eq ${noConfigFileExitCode} ]; then
if [ "${hookName}" = "pre-commit" ]; then
echo "[rusty-hook] rusty-hook git hooks are configured, but no config file was found"
echo "[rusty-hook] In order to use rusty-hook, your project must have a config file"
echo "[rusty-hook] See https://github.com/swellaby/rusty-hook#configure for more information about configuring rusty-hook"
echo
echo "[rusty-hook] If you were trying to remove rusty-hook, then you should also delete the git hook files to remove this warning"
echo "[rusty-hook] See https://github.com/swellaby/rusty-hook#removing-rusty-hook for more information about removing rusty-hook from your project"
echo
fi
exit 0
else
echo "[rusty-hook] Configured hook command failed"
echo "[rusty-hook] ${hookName} hook rejected"
# shellcheck disable=SC2086
exit ${rustyHookExitCode}
fi
}
# shellcheck source=src/hook_files/semver.sh
. "$(dirname "$0")"/semver.sh