forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_diff.go
46 lines (39 loc) · 839 Bytes
/
print_diff.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
package cmd
import (
"fmt"
boshui "github.com/cloudfoundry/bosh-cli/ui"
)
type Diff struct {
lines [][]interface{}
}
func NewDiff(lines [][]interface{}) Diff {
return Diff{
lines: lines,
}
}
func (d Diff) Print(ui boshui.UI) {
for _, line := range d.lines {
lineMod, _ := line[1].(string)
if lineMod == "added" {
ui.BeginLinef("+ %s\n", line[0])
} else if lineMod == "removed" {
ui.BeginLinef("- %s\n", line[0])
} else {
ui.BeginLinef(" %s\n", line[0])
}
}
}
func (d Diff) String() string {
var result string
for _, line := range d.lines {
lineMod, _ := line[1].(string)
if lineMod == "added" {
result += fmt.Sprintf("+ %s\n", line[0])
} else if lineMod == "removed" {
result += fmt.Sprintf("- %s\n", line[0])
} else {
result += fmt.Sprintf(" %s\n", line[0])
}
}
return result
}