]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm/sync_changes.go
changes: refactor into separate function and add basic tests
[safcm/safcm.git] / cmd / safcm / sync_changes.go
index 46349116a602d1fb7e389b7b089116aabbbbd418..1ec3cb60b435632fedac3e95b975239d1f12160e 100644 (file)
@@ -30,6 +30,30 @@ import (
 // the remote helper is untrusted and must be either escaped with %q or by
 // calling EscapeControlCharacters().
 
+func (s *Sync) formatChanges(resp safcm.MsgSyncResp) string {
+       var changes []string
+       if len(resp.FileChanges) > 0 {
+               changes = append(changes,
+                       s.formatFileChanges(resp.FileChanges))
+       }
+       if len(resp.PackageChanges) > 0 {
+               changes = append(changes,
+                       s.formatPackageChanges(resp.PackageChanges))
+       }
+       if len(resp.ServiceChanges) > 0 {
+               changes = append(changes,
+                       s.formatServiceChanges(resp.ServiceChanges))
+       }
+       if len(resp.CommandChanges) > 0 {
+               changes = append(changes,
+                       s.formatCommandChanges(resp.CommandChanges))
+       }
+       if len(changes) == 0 {
+               return ""
+       }
+       return "\n" + strings.Join(changes, "\n")
+}
+
 func (s *Sync) formatFileChanges(changes []safcm.FileChange) string {
        var buf strings.Builder
        fmt.Fprintf(&buf, "changed %d file(s):", len(changes))
@@ -226,10 +250,6 @@ func (s *Sync) formatDiff(diff string) string {
 }
 
 func indentBlock(x string, sep string) string {
-       if x == "" {
-               return ""
-       }
-
        lines := strings.Split(x, "\n")
        if lines[len(lines)-1] == "" {
                lines = lines[:len(lines)-1]