-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcli.sh
137 lines (126 loc) · 3.42 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
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
#!/bin/bash
# Define help message
print_help() {
echo "Allowed options:"
echo ""
echo "Generic options:"
echo " -h [ --help ] produce help message"
echo ""
echo "Project setup options:"
echo " gensln <args> configure the project. Run gensln --help for a list of available options."
echo " buildsln <args> build the project. Run buildsln --help for a list of available options."
echo " installsln <args> install the project. Run installsln --help for a list of available options."
echo ""
echo "Project run options:"
echo " run <args> run the application. Run run --help for a list of available options."
}
# Trigger help if no arguments are passed
if [[ $# -eq 0 ]]; then
print_help
exit 0
fi
# Parse command line arguments
found_gensln=false
found_gensln_parse_help=false
found_buildsln=false
found_buildsln_parse_help=false
found_installsln=false
found_installsln_parse_help=false
found_run=false
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h | --help)
if [[ "$found_gensln" = true ]]; then
gensln_options="$gensln_options $key"
shift # past key
elif [[ "$found_buildsln" = true ]]; then
buildsln_options="$buildsln_options $key"
shift # past key
else
print_help
exit 0
fi
;;
gensln)
found_gensln=true
found_gensln_parse_help=true
shift # past argument
;;
buildsln)
found_buildsln=true
found_buildsln_parse_help=true
found_gensln_parse_help=false
shift # past argument
;;
installsln)
found_installsln=true
found_installsln_parse_help=true
found_gensln_parse_help=false
found_buildsln_parse_help=false
shift # past argument
;;
run)
found_run=true
found_gensln_parse_help=false
found_buildsln_parse_help=false
found_installsln_parse_help=false
shift # past argument
;;
*) # unknown option
if [[ "$found_gensln_parse_help" = true ]]; then
gensln_options="$gensln_options $key"
shift # past key
elif [[ "$found_buildsln_parse_help" = true ]]; then
buildsln_options="$buildsln_options $key"
shift # past key
elif [[ "$found_installsln_parse_help" = true ]]; then
installsln_options="$installsln_options $key"
shift # past key
elif [[ "$found_run" = true ]]; then
run_options="$run_options $key"
shift # past key
else
echo "Unknown option: $key"
echo "Usage: $0 [gensln|buildsln|run] [options]"
exit 33
fi
;;
esac
done
# Run gensln
if [[ $found_gensln = true ]]; then
echo "-- Running gensln with options: $gensln_options"
. ./tools/gensln.sh $gensln_options
if [[ $? -ne 0 ]]; then
echo "-- Failed to generate solution"
exit 33
fi
fi
# Run buildsln
if [[ $found_buildsln = true ]]; then
echo "-- Running buildsln with options: $buildsln_options"
. ./tools/buildsln.sh $buildsln_options
if [[ $? -ne 0 ]]; then
echo "-- Failed to build solution"
exit 33
fi
fi
# Run installsln
if [[ $found_installsln = true ]]; then
echo "-- Running installsln with options: $installsln_options"
. ./tools/installsln.sh $installsln_options
if [[ $? -ne 0 ]]; then
echo "-- Failed to install solution"
exit 33
fi
fi
# Run run
if [[ $found_run = true ]]; then
echo "-- Running run with options: $run_options"
./tools/run.sh $run_options
if [[ $? -ne 0 ]]; then
echo "-- Failed to run solution"
exit 33
fi
fi