-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun
More file actions
executable file
·143 lines (117 loc) · 3.83 KB
/
run
File metadata and controls
executable file
·143 lines (117 loc) · 3.83 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
################################################################################
# WARNING: Please make this shell not working-directory dependant, for example
# instead of using 'ls blabla', use 'ls "${STACK_DIR}/blabla"'
#
# WARNING: Don't use "cd" in this shell, use it in a subshell instead,
# for example ( cd blabla && do_blabla ) or $( cd .. && do_blabla )
################################################################################
# ---------------------------------------------------------------------
# Variables
# ---------------------------------------------------------------------
# Check on OS type for stack directory
# Mac OS
if [[ "$(uname)" == "Darwin" ]]; then
# check if greadlink is installed
if ! command -v greadlink &> /dev/null; then
echo "greadlink could not be found, please install it with 'brew install coreutils'"; exit 1
fi
readonly STACK_DIR="$(dirname "$(greadlink -m "${0}")")"
# Windows
elif [[ "$(expr substr "$(uname -s)" 1 10)" == "MINGW64_NT" ]]; then
readonly STACK_DIR="$(dirname "$(readlink -m "${0}")")"
# Linux
else
readonly STACK_DIR="$(dirname "$(readlink -m "${0}")")"
fi
source "${STACK_DIR}/bin/lib/lib-core.sh"
# ---------------------------------------------------------------------
# Import Libraries
# ---------------------------------------------------------------------
importLib "lib/lib-helpify.sh"
importLib "lib/lib-messages.sh"
importLib "lib/lib-services.sh"
importLib "lib/lib-commands.sh"
# -----------------------------------------------------------------------------
# Helpers
# -----------------------------------------------------------------------------
usage () {
# show usage for all commands
need_usage4help="true"
# add logo
logo
# add version info (use function getVersion)
versionInfo
echo;
helpify_title "" "[OPTIONS...] COMMAND [OPTIONS...]"
helpify_subtitle "It allows you to easily orchestrate the development stack for GDRCD"; echo;
helpify_subtitle "OPTIONS:"
helpify "-h, --help" "Show this help"
helpify_separator
#
usageCommands
#
usageSubDirsCommands
}
usageService () {
# show usage for service commands
need_help="true";
need_usage4help="true"
#
usageServiceCommands "${1}"
# force exit
exit 0;
}
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
# Get environment variables
importEnv
# Check if the version is up to date
checkVersion
# If no arguments are passed, show usage
if [[ $# -eq 0 ]]; then
need_help="true";
fi
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
need_help="true"; shift ;;
-*|--*)
prompt -e "Error! Unrecognized stack option: ${1}";
has_any_error="true"; shift ;;
*)
# if is a valid command, run it
if isCommand "$1" ; then
# shellcheck source=bin
source "${COMMANDS_DIR}/$1";
exit 0;
# otherwise, check if is a valid sub-command
elif isSubCommand "$1"; then
# check if there is a second argument
if [[ $# -gt 1 ]]; then
# if is a valid command, run it
if isCommand --abs-path "${COMMANDS_DIR}/$1/$2"; then
# shellcheck source=bin
source "${COMMANDS_DIR}/$1/$2";
exit 0;
# otherwise, if there is no other entries, show error
else
prompt -e "Error! Unrecognized $1 command: ${2}"; has_any_error="true";
break;
fi
else
usageService "$1" || exit 1
fi
# otherwise, if there is no other entries, show error
else
prompt -e "Error! Unrecognized stack command: ${*}"; has_any_error="true";
break;
fi
shift ;;
esac
done
# Execute post argument parsing checks
finalize_argument_parsing
echo;