-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathscript.sh
92 lines (83 loc) · 2.54 KB
/
script.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
#!/bin/bash
# ----------------------------------------------------------------------
# Help function on commands.
# ----------------------------------------------------------------------
helpFunction()
{
echo ""
echo "Usage: $0"
echo ""
echo "Options: "
echo " -c composer command"
echo " -n npm command"
echo " -a artisan command"
echo ""
echo "For example:"
echo "If you want to run this command 'php artisan migrate' simply write this:"
echo -e "\t -a migrate"
exit 1
}
# ----------------------------------------------------------------------
# Run PHP artisan commands.
# ----------------------------------------------------------------------
artisanCommands()
{
echo "Runnin php artisna $parameterA"
docker exec app php artisan $parameterA
exit 1
}
# ----------------------------------------------------------------------
# Run npm commands.
# ----------------------------------------------------------------------
npmCommands()
{
echo "Runnin npm $parameterN"
docker exec npm npm $parameterN
exit 1
}
# ----------------------------------------------------------------------
# Run composer commands.
# ----------------------------------------------------------------------
composerCommands()
{
echo "Runnin composer $parameterC"
docker exec app composer $parameterC
exit 1
}
while getopts "a:n:c:" opt
do
case "$opt" in
a ) parameterA="$OPTARG" ;;
n ) parameterN="$OPTARG" ;;
c ) parameterC="$OPTARG" ;;
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac
done
# ----------------------------------------------------------------------
# Check parameter a for artisan commands.
# ----------------------------------------------------------------------
if [ "$parameterA" ]
then
artisanCommands
fi
# ----------------------------------------------------------------------
# Check parameter c for composer commands.
# ----------------------------------------------------------------------
if [ "$parameterC" ]
then
composerCommands
fi
# ----------------------------------------------------------------------
# Check parameter n for npm commands.
# ----------------------------------------------------------------------
if [ "$parameterN" ]
then
npmCommands
fi
# ----------------------------------------------------------------------
# Print helpFunction in case parameters are empty
# ----------------------------------------------------------------------
if [ -z "$parameterA" ] || [ -z "$parameterN" ] || [ -z "$parameterC" ]
then
helpFunction
fi