-
Notifications
You must be signed in to change notification settings - Fork 0
/
skritt
88 lines (75 loc) · 2.28 KB
/
skritt
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env zsh
# Copyright 2020-2024, Hojin Koh
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# The central include file
set -o err_return
set -o no_unset
set -o pipefail
# Setup our own SHLVL
export SKRITT_SHLVL=$[${SKRITT_SHLVL-0}+1]
if [[ ${SKRITT_CONFIG_IGNORE_DOTENV-} != true ]]; then
if [[ -r .env ]]; then
source .env
fi
fi
# Open file descriptor 5 (show only, no logging) if not yet done
if [[ ! -e /dev/fd/5 ]]; then
exec 5>&2
fi
# Open file descriptor 6 (logging only, no show) if not yet done
# This is default value, may be overriden by log files later
if [[ ! -e /dev/fd/6 ]]; then
exec 6>/dev/null
fi
# Setup path for our executables
if [[ -z ${SKRITT_ROOT_DIR-} ]]; then
export SKRITT_ROOT_DIR=${0:a:h}
fi
source $SKRITT_ROOT_DIR/lib/flow.zsh
source $SKRITT_ROOT_DIR/lib/opts.zsh
source $SKRITT_ROOT_DIR/lib/msg.zsh
source $SKRITT_ROOT_DIR/lib/logging.zsh
source $SKRITT_ROOT_DIR/lib/fs.zsh
if declare -f skrittLibraryInit >/dev/null; then
skrittLibraryInit
fi
opt -Skritt check false "Check whether this script need to run (return false=need)"
opt -Skritt force false "Always run the script even if there's no need"
debug "Begin script: $ZSH_ARGZERO $*"
if declare -f setupArgs >/dev/null; then
setupArgs
fi
SKRITT::FLOW::preparse "$@"
source $SKRITT_ROOT_DIR/bin/parseopts
SKRITT::FLOW::postparse "$@"
skrittNeedToRun=true
if declare -f check >/dev/null; then
check && skrittNeedToRun=false || skrittNeedToRun=true
fi
if [[ $check == true ]]; then
unset -f TRAPEXIT
if [[ $skrittNeedToRun == true ]]; then
exit 1
fi
exit 0
else
if [[ $skrittNeedToRun == true || $force == true ]]; then
SKRITT::FLOW::prerun "$@"
main "$@"
SKRITT::FLOW::postrun "$@"
else
unset -f TRAPEXIT
debug "Check passed, no need to run $skrittCommandLineOriginal"
fi
fi