/
gob.sh
executable file
·155 lines (148 loc) · 4.7 KB
/
gob.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Gob and Reveler, Go/Revel Project Management
# Implemented as a bash function
# To use, source this file from your bash profile
#
# Implemented by Tim Anema <timanema@gmail.com>
GOB_VERSION="0.1.1"
# Auto detect the GOB_DIR
if [ ! -d "$GOB_DIR" ]; then
export GOB_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd)
fi
cd (){
builtin cd $@
if [ "x$GOPATH" = "x" ]; then
gob_get_proj_dir
elif [[ $PWD != $GOPATH* ]]; then
export PATH=$(echo ${PATH#$GOPATH/bin:})
export GOPATH=""
gob_get_proj_dir
fi
}
gob_get_proj_dir() {
local dir="$(pwd)"
while [[ $dir != "/" ]]; do
if [[ -e "${dir}/.goproj" ]]; then
export GOPATH="${dir}"
export PATH=$GOPATH/bin:$PATH
break
fi
dir=$(dirname "${dir}")
done
}
gob (){
if [ $# -lt 1 ]; then
gob help && return
fi
case $1 in
"help")
echo ""
echo "Gob"
echo ""
echo "Use:"
echo " gob help Show this message"
echo " gob init Create a .goproj file in the pwd, marking it as the root of a project."
echo " gob new,n Creates a new directory with a .goproj and .gitignore file in it."
echo " gob version Displays version Number."
echo ""
echo "Example:"
echo " gob init"
echo " gob new myproj"
echo ""
;;
"init")
if [ "x$GOPATH" = "x" ]; then
# add .goproj to current directory for use with gob
echo "Warning, only do this in the root of your project directory"
echo "Continue (y/n)?"
read choice
case "$choice" in
y|Y ) touch .goproj && echo "Created .goproj" ;;
esac
else
echo "Cannot (or will not) make a go project inside another go project"
fi
;;
"new" | "n")
# create directory with .goproj in it already and .gitignore
if [ "x$GOPATH" = "x" ]; then
mkdir $2 && touch $2/.goproj && cp $GOB_DIR/Go.gitignore $2/.gitignore && echo "Created $2"
else
echo "Cannot (or will not) make a go project inside another go project"
fi
;;
"version" ) echo $GOB_VERSION;;
"program" )
echo "Gob's Program: Y/N?"
echo "?"
read choice
case "$choice" in
y|Y )
while [[ 1 = 1 ]]; do
printf "Penus "
done
;;
esac
;;
* ) gob help;;
esac
}
reveler () {
if [ $# -lt 1 ]; then
reveler help && return
fi
case $1 in
"help")
echo ""
echo "Reveler"
echo ""
echo "Use:"
echo " reveler help Show this message"
echo " reveler init Create a .goproj file in the pwd, marking it as the root of a project."
echo " reveler new,n Creates a new directory with a .goproj and .gitignore file in it."
echo " It then gets revel and builds it."
echo " reveler run,r Will run the revel project."
echo " reveler debug,d Will build the app and open a gdb console with the project ready to run."
echo " reveler version Displays version Number."
echo ""
echo "Example:"
echo " reveler init"
echo " reveler new myproj"
echo ""
;;
"init" ) gob init;;
"new" | "n")
gob new $2 && cd $2
echo "Getting revel"
go get github.com/robfig/revel || { echo 'go get failed' ; return 1; }
echo "Building revel"
go build -o bin/revel github.com/robfig/revel/cmd || { echo 'go build failed' ; return 1; }
revel new $2 && cd src/$2
;;
"run" | "r" | "server" | "s" )
# run a revel app from the goproj root
if [ "x$GOPATH" = "x" ]; then
echo "Oops, you are not in a project directory"
else
revel run ${GOPATH##*/}
fi
;;
"debug" | "d" |"console" | "c" )
# run a revel console from the goproj root
if [ "x$GOPATH" = "x" ]; then
echo "Oops, you are not in a project directory"
else
echo "####################################################"
echo "# Warning #"
echo "# -------------------------------------------------#"
echo "# This will be a built version of your app, any #"
echo "# changes will not be reflected in debug, revel #"
echo "# does not support this at the moment. #"
echo "####################################################"
local project_name=${GOPATH##*/}
revel clean test &> /dev/null && revel build $project_name $GOPATH/tmp/$project_name && (echo r ; cat) | gdb --args $GOPATH/bin/$project_name -importPath $project_name -srcPath "$GOPATH/src" -runMode dev
fi
;;
"version" ) echo $GOB_VERSION;;
* ) reveler help;;
esac
}