]> 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 7ef0541fcb4809b17669c2acda6a1e0f8c357bc0..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))