-
Notifications
You must be signed in to change notification settings - Fork 1
/
print.go
50 lines (43 loc) · 1.15 KB
/
print.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
package bootstrap
import (
"fmt"
"github.com/hephbuild/heph/lcache"
"github.com/hephbuild/heph/utils/xfs"
"io"
"os"
)
func PrintTargetOutputContent(target *lcache.Target, output string) error {
return targetOutputsFunc(target, output, func(path xfs.Path) error {
f, err := os.Open(path.Abs())
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(os.Stdout, f)
return err
})
}
func PrintTargetOutputPaths(target *lcache.Target, output string) error {
return targetOutputsFunc(target, output, func(path xfs.Path) error {
fmt.Println(path.Abs())
return nil
})
}
func targetOutputsFunc(target *lcache.Target, output string, f func(path xfs.Path) error) error {
paths := target.ActualOutFiles().All()
if output != "" {
if !target.ActualOutFiles().HasName(output) {
return fmt.Errorf("%v: output `%v` does not exist", target.Addr, output)
}
paths = target.ActualOutFiles().Name(output)
} else if len(paths) == 0 {
return fmt.Errorf("%v: does not output anything", target.Addr)
}
for _, path := range paths.WithRoot(target.OutExpansionRoot().Abs()) {
err := f(path)
if err != nil {
return err
}
}
return nil
}