-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.go
48 lines (42 loc) · 1.19 KB
/
dependencies.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
package diagnostics
import (
"fmt"
"github.com/nestoca/joy/internal/dependencies"
"github.com/nestoca/joy/internal/style"
)
func diagnoseDependencies(required, optional []*dependencies.Dependency) (group Group) {
group.Title = "Dependencies"
group.topLevel = true
group.AddSubGroup(func() (group Group) {
group.Title = "Required dependencies"
for _, dep := range required {
if !dep.IsInstalled() {
group.AddMsg(failed, fmt.Sprintf("%s missing (see %s)", style.Code(dep.Command), style.Link(dep.Url)))
continue
}
group.AddMsg(success, fmt.Sprintf("%s installed", style.Code(dep.Command)))
}
return
}())
group.AddSubGroup(func() (group Group) {
group.Title = "Optional dependencies"
for _, dep := range optional {
if !dep.IsInstalled() {
group.AddMsg(
info,
fmt.Sprintf("%s missing (see %s) but only required by:", style.Code(dep.Command), style.Link(dep.Url)),
func() (msgs Messages) {
for _, cmd := range dep.RequiredBy {
msgs = append(msgs, msg(info, style.Code("joy "+cmd)))
}
return
}()...,
)
continue
}
group.AddMsg(success, fmt.Sprintf("%s installed", style.Code(dep.Command)))
}
return
}())
return
}