This repository was archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeps.fish
executable file
·153 lines (126 loc) · 3.18 KB
/
deps.fish
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
#!/usr/bin/env fish
# Prints help message
function print_usage
echo "Install or update project dependencies
Usage: deps.fish <COMMAND>
COMMAND:
install installs project dependencies
update updates project dependencies" >&2
end
function fatal -a msg -d "Prints error message and exits"
set_color red
printf "$msg\n" >&2
exit 1
end
# Checks if current system has all required dependencies
function check_system
if ! type -q go
fatal "Go is not installed"
end
if ! type -q tar
fatal "Tar is not installed"
end
if ! type -q curl
fatal "Curl is not installed"
end
set gobin (go env GOBIN)
if test -z "$gobin"
fatal "GOBIN is not set"
end
end
# Installs project dependencies
# Args:
# $forced - wherever to re-install/update dependencies
function install_deps -a forced
set -x GO111MODULE on
pushd (go env GOBIN)
install_gopls $forced
install_goose $forced
install_delve $forced
popd
install_sqlc $forced
end
# Installs gopls LSP
# Args:
# $forced - wherever to update gopls if already installed
function install_gopls -a forced
if ! type -q gopls || test -n "$forced"
echo "Installing 'gopls'" >&2
go get golang.org/x/tools/gopls@latest
end
end
# Installs goose SQL migration tool
# Args:
# $forced - wherever to update goose if already installed
function install_goose -a forced
if ! type -q goose || test -n "$forced"
echo "Installing 'goose'" >&2
go get -u github.com/pressly/goose/cmd/goose
end
end
# Installs delve debugger
# Args:
# $forced - wherever to update delve if already installed
function install_delve -a forced
if ! type -q dlv || test -n "$forced"
echo "Installing 'delve'" >&2
go get -u github.com/go-delve/delve/cmd/dlv
end
end
# Installs sqlc SQL/Go generation tool
# Args:
# $forced - wherever to update sqlc if already installed
function install_sqlc -a forced
if ! type -q sqlc || test -n "$forced"
set tmpdir (mktemp -d)
trap "rm -rf $tmpdir" EXIT
echo "Installing 'sqlc'" >&2
set system (uname -s | string lower)
set arch (uname -m)
if test $system = linux -a $arch = x86_64
download_sqlc_linux $tmpdir
else if test $system = darwin -a $arch = x86_64
download_sqlc_darwin $tmpdir
else
fatal "'sqlc' binary is not available for your platform"
end
mv $tmpdir/sqlc $GOBIN/sqlc
end
end
# Downloads sqlc for linux platform
# Args:
# $dir - path to download directory
function download_sqlc_linux -a dir
set path $dir/sqlc.tgz
set url "https://bin.equinox.io/c/gvM95th6ps1/sqlc-devel-linux-amd64.tgz"
curl -o $path -OL $url
pushd $dir
tar zxf $path
popd
end
# Downloads sqlc for macOS platform
# Args:
# $dir - path to download directory
function download_sqlc_darwin -a dir
set path $dir/sqlc.zip
set url "https://bin.equinox.io/c/gvM95th6ps1/sqlc-devel-darwin-amd64.zip"
curl -o $path -OL $url
pushd $dir
unzip $path >/dev/null
popd
end
function main
check_system
set cmd $argv[1]
switch "$cmd"
case install
install_deps
case update
install_deps "forced"
case --help -h
print_usage
case "*"
fatal "Unknown command $cmd\nTry '--help' for help"
end
end
main $argv