-
Notifications
You must be signed in to change notification settings - Fork 19
/
asty.v
37 lines (35 loc) · 1.61 KB
/
asty.v
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
// Copyright (c) 2024 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
import os
const gopath_res = os.execute('go env GOPATH')
const gopath_bin = os.join_path(gopath_res.output.trim_space(), '/bin')
const asty_executable_name = if os.user_os() == 'windows' { 'asty.exe' } else { 'asty' }
const full_path_to_asty = os.join_path(gopath_bin, asty_executable_name)
fn ensure_asty_is_installed() ! {
if _ := os.find_abs_path_of_executable(asty_executable_name) {
return
}
// Ensure that $GOPATH/bin is in PATH, and that asty is present, so invokin `asty` works:
if gopath_res.exit_code != 0 {
return error('Failed to find Go. Visit https://go.dev/dl/ to see instructions, on how to install it.')
}
os.setenv('GOBIN', gopath_bin, true)
os.setenv('PATH', os.getenv('PATH') + os.path_delimiter + gopath_bin, true)
if !os.exists(gopath_bin) {
os.mkdir_all(gopath_bin)!
}
if _ := os.find_abs_path_of_executable(asty_executable_name) {
return
}
// Check if asty is installed:
if !os.exists(full_path_to_asty) {
println('asty not found in ${full_path_to_asty}, installing...')
if os.system('go install github.com/asty-org/asty@latest') != 0 {
return error('Failed to install asty. Please run: `go install github.com/asty-org/asty@latest` manually, and then make sure, that ${gopath_bin} is in your \$PATH.')
}
}
os.find_abs_path_of_executable(asty_executable_name) or {
os.system('ls -la ${gopath_bin}')
return error('asty is still not installed in ${gopath_bin} ... Please run `go install github.com/asty-org/asty@latest`.')
}
}