-
Notifications
You must be signed in to change notification settings - Fork 0
/
executable.go
64 lines (51 loc) · 1.65 KB
/
executable.go
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
package diagnostics
import (
"fmt"
"os"
"path/filepath"
"golang.org/x/mod/semver"
"github.com/nestoca/joy/internal/config"
"github.com/nestoca/joy/internal/style"
)
type ExecutableOptions struct {
LookupExecutable func() (string, error)
AbsolutePath func(string) (string, error)
}
func diagnoseExecutable(cfg *config.Config, cliVersion string, opts ExecutableOptions) (group Group) {
if opts.LookupExecutable == nil {
opts.LookupExecutable = os.Executable
}
if opts.AbsolutePath == nil {
opts.AbsolutePath = filepath.Abs
}
group.Title = "Executable"
group.topLevel = true
group.AddMsg(info, label("Version", cliVersion))
// Executable version
if !semver.IsValid(cliVersion) {
group.AddMsg(warning, fmt.Sprintf("Version is not in semver format and cannot be compared with minimum of %s required by catalog", style.Code(cfg.MinVersion)))
return
}
if semver.Compare(cliVersion, cfg.MinVersion) < 0 {
group.AddMsg(
failed,
fmt.Sprintf("Version does not meet minimum of %s required by catalog", style.Code(cfg.MinVersion)),
msg(hint, fmt.Sprintf("Update joy using: %s", style.Code("brew update && brew upgrade joy"))),
)
return
}
group.AddMsg(success, fmt.Sprintf("Version meets minimum of %s required by catalog", style.Code(cfg.MinVersion)))
// Executable path
execPath, err := opts.LookupExecutable()
if err != nil {
group.AddMsg(failed, "Failed to get executable path: "+err.Error())
return
}
absolutePath, err := opts.AbsolutePath(execPath)
if err != nil {
group.AddMsg(failed, "Failed to get absolute path of executable: "+err.Error())
return
}
group.AddMsg(info, label("File path", absolutePath))
return
}