-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.template.sh
75 lines (64 loc) · 1.73 KB
/
script.template.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
68
69
70
71
72
73
74
75
#!/bin/sh
set -euC
usage () {
cat <<EOF
Usage: $0 [CATALA-FILE] [OPTIONS]
Format the given CATALA-FILE and output the result.
When no CATALA-FILE is provided, the standard input will be read
however the --language argument becomes mandatory.
--help Show this help and quit
-l <lang>
--language <lang> Configure the formatting parser's language.
Possible values are: 'catala_en', 'catala_fr' or 'catala_pl'.
EOF
}
die () {
printf >&2 "$@"
printf '\n'
usage
exit 2
}
CATALA_LANG=""
INPUT_FILE=""
while [ $# -gt 0 ]; do
arg=$1
shift
case $arg in
--language|-l)
CATALA_LANG=$1
shift
;;
--help)
usage
exit 0
;;
*)
if [ "$INPUT_FILE" = "" ]; then
INPUT_FILE=$arg
if ! [ -f $INPUT_FILE ]; then
die "Given input file '%s' is not a regular file" "$arg"
fi
else
die 'Multiple input file arguments provided. Expected only one.'
fi
esac
done
if [ "$CATALA_LANG" = "" ]; then
extension="${INPUT_FILE##*.}"
case $extension in
"catala_en"|"catala_fr"|"catala_pl")
CATALA_LANG=$extension
;;
*)
die "Cannot infer the parser's language.\nYou can manually set it with the --language option."
esac
else
case $CATALA_LANG in
"catala_en"|"catala_fr"|"catala_pl")
break
;;
*)
die "Invalid specified language '%s'.\nPossible values are 'catala_en', 'catala_fr' or 'catala_pl'." "$CATALA_LANG"
esac
fi
# Evaluated invokation is generated here