-
Notifications
You must be signed in to change notification settings - Fork 0
/
modules_localize.sh
executable file
·62 lines (53 loc) · 1.28 KB
/
modules_localize.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
#!/usr/bin/env bash
helpfunc()
{
echo "modules_localize allows you to temporarily replace a Go module with a local version"
echo "replace [local pkg path] [module] - replace module to local version"
echo "undo [local pkg path] [module] - revert to the original version"
echo "example: modules_localize.sh replace ~/go/src/github.com/yarelm/somemodule github.com/yarelm/somemodule"
echo "example: modules_localize.sh undo ~/go/src/github.com/yarelm/somemodule github.com/yarelm/somemodule"
}
PKGPATH=$2
MODULES=$3
replace()
{
if [ ! -f $PKGPATH/go.mod ]; then
# In this case, this is not a Go modules supported pkg. Let's create a dummy go.mod file
touch $PKGPATH/go.mod
touch $PKGPATH/gomod.temp
fi
go mod edit -replace=$MODULES=$PKGPATH go.mod
}
undo()
{
if [ -f $PKGPATH/gomod.temp ]; then
# Remove the dummy file if exists
rm $PKGPATH/go.mod
rm $PKGPATH/gomod.temp
fi
go mod edit -dropreplace=$MODULES go.mod
}
#filename=default
while (( $# > 0 ))
do
opt="$1"
shift
case $opt in
help)
helpfunc
exit 0
;;
replace)
replace
exit 0
;;
undo)
undo
exit 0
;;
*)
helpfunc
exit 0
;;
esac
done