This repository was archived by the owner on Nov 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsea.bash
More file actions
executable file
·147 lines (122 loc) · 3.19 KB
/
sea.bash
File metadata and controls
executable file
·147 lines (122 loc) · 3.19 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
144
145
146
147
#!/bin/bash
path="$(dirname "$0" | sed s/' '/'\\ '/g)"
main="$path/app/build/distributions/app/bin/app"
version() {
printf "Sea 0.0.0\n"
}
update() {
printf "Not Implemented\n"
}
printu() {
printf " %-20s" "$1"
printf "\t%-52s\n" "$2"
}
usage() {
printf "Usage: sea [OPTIONS]... [DIR|FILE]... \n"
printf "Compiles Sea code in FILEs or in DIRs and subdirs.\n\n"
printf "OPTIONS:\n"
printu "-d, --debug" "writes compiler debug information to a file."
printu "-h, --help" "prints the sea command's usage information."
printu "-u, --update" "uses git to update Sea to the latest version."
printu "--version" "prints the sea command's version information."
printf "\n"
printu "-o, --out=OUT" "specifies the output directory to compile to;"
printu "" "all files will be written into OUT, which is"
printu "" "the current directory by default; The directory"
printu "" "will be created if it does not exist."
}
options="-"
out_dir="."
files=()
add() {
options="${options}$1"
}
get_arg_return=""
get_arg() {
if [[ "${OPTARG}" == *"="* ]]
then
get_arg_return="${OPTARG#*=}"
return 0
fi
printf "Must supply an argument to %s.\n" "$1"
exit 1
}
get_single_arg() {
get_arg "$1"
char="${get_arg_return::1}"
if [[ "$2" == "" || "$2" == *"$char"* ]]
then
get_arg_return="$char"
return 0
fi
printf "Argument must be one of '%s'.\n" "$2"
exit 3
}
while getopts ":-:hduo:" arg
do
case "${arg}" in
-)
case "${OPTARG}" in
"help")
usage
exit 0 ;;
"debug")
add "d" ;;
"update")
update
exit "$?" ;;
"version")
version
exit 0 ;;
"out"|"out="*)
get_arg "--out"
out_dir="$get_arg_return" ;;
*)
printf "Invalid options: --%s.\n" "${OPTARG}"
exit 2 ;;
esac ;;
"h")
usage
exit 0 ;;
"d")
add "d" ;;
"u")
update
exit "$?" ;;
"o")
get_arg "-o"
out_dir="$get_arg_return" ;;
:)
printf "Must supply an argument to -%s.\n" "${OPTARG}"
exit 1 ;;
?)
printf "Invalid options: -%s.\n" "${OPTARG}"
exit 2 ;;
esac
done
for (( i=1; i<= "$#"; i++ ))
do
[[ "${!i}" == -* ]] && continue
if [[ ! -f "${!i}" && ! -d "${!i}" ]]
then
printf "'%s' is not an existing file or directory.\n" "${!i}"
exit 4
fi
hy_files=()
mapfile -d '' hy_files < <(find "${!i}" -type f -name "*.sea" -print0)
files+=("${hy_files[@]}")
done
if [[ "${files[*]}" == "" ]]
then
printf "Requires input files or directories to compile.\n"
exit 6
fi
mapfile -d '' files < <(printf "%s\0" "${files[@]}" | sort -uz)
mkdir -p "$out_dir"
out_dir="$(realpath --relative-base=. "$out_dir")"
printf "\n"
if ! eval "$main" "$options" "$out_dir" "${files[*]@Q}"
then
exit "$?"
fi
exit 0