X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fsync_changes.go;h=2650bb46062b33ab0f86e75d9b0f0cb1643bf556;hb=6f7b878074e898edc4942117d590f51d79a4d009;hp=6327fd9addbaec497a31452a635082cb6f65b32e;hpb=cfcc39441d8e9b1f003b8d5c02240e7186bfc2d1;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/sync_changes.go b/cmd/safcm/sync_changes.go index 6327fd9..2650bb4 100644 --- a/cmd/safcm/sync_changes.go +++ b/cmd/safcm/sync_changes.go @@ -49,18 +49,29 @@ func (s *Sync) formatChanges(resp safcm.MsgSyncResp) string { s.formatCommandChanges(resp.CommandChanges)) } if len(changes) == 0 { - return "" + // Notify user that the host was synced successfully + return "no changes" } - return "\n" + strings.Join(changes, "\n") + + x := strings.Join(changes, "\n") + // If quiet is used and only commands without output were executed + // then don't prepend a newline so that the whole change output of a + // host fits in a single line. This makes the output much more + // readable with multiple hosts. + if strings.Count(x, "\n") == 1 { + return x + } + return "\n" + x } func (s *Sync) formatFileChanges(changes []safcm.FileChange) string { var buf strings.Builder - fmt.Fprintf(&buf, "changed %d file(s):", len(changes)) if s.config.DryRun { - fmt.Fprintf(&buf, " (dry-run)") + fmt.Fprintf(&buf, "will change %d file(s): (dry-run)\n", + len(changes)) + } else { + fmt.Fprintf(&buf, "changed %d file(s):\n", len(changes)) } - fmt.Fprintf(&buf, "\n") for _, x := range changes { fmt.Fprintf(&buf, "%s:", s.formatTarget(x.Path)) @@ -106,7 +117,6 @@ func (s *Sync) formatFileChanges(changes []safcm.FileChange) string { } fmt.Fprintf(&buf, "\n") } - return buf.String() } func formatFileType(info safcm.FileChangeInfo) string { @@ -132,11 +142,12 @@ func formatFilePerm(info safcm.FileChangeInfo) string { func (s *Sync) formatPackageChanges(changes []safcm.PackageChange) string { var buf strings.Builder - fmt.Fprintf(&buf, "installed %d package(s):", len(changes)) if s.config.DryRun { - fmt.Fprintf(&buf, " (dry-run)") + fmt.Fprintf(&buf, "will install %d package(s): (dry-run)\n", + len(changes)) + } else { + fmt.Fprintf(&buf, "installed %d package(s):\n", len(changes)) } - fmt.Fprintf(&buf, "\n") for _, x := range changes { // TODO: indicate if installation failed fmt.Fprintf(&buf, "%s\n", s.formatTarget(x.Name)) @@ -146,11 +157,12 @@ func (s *Sync) formatPackageChanges(changes []safcm.PackageChange) string { func (s *Sync) formatServiceChanges(changes []safcm.ServiceChange) string { var buf strings.Builder - fmt.Fprintf(&buf, "modified %d service(s):", len(changes)) if s.config.DryRun { - fmt.Fprintf(&buf, " (dry-run)") + fmt.Fprintf(&buf, "will modify %d service(s): (dry-run)\n", + len(changes)) + } else { + fmt.Fprintf(&buf, "modified %d service(s):\n", len(changes)) } - fmt.Fprintf(&buf, "\n") for _, x := range changes { var info []string if x.Started { @@ -187,9 +199,13 @@ func (s *Sync) formatCommandChanges(changes []safcm.CommandChange) string { } var buf strings.Builder - fmt.Fprintf(&buf, "executed %d command(s)", len(changes)) + if s.config.DryRun { + fmt.Fprintf(&buf, "will execute %d command(s)", len(changes)) + } else { + fmt.Fprintf(&buf, "executed %d command(s)", len(changes)) + } if noOutput > 0 && !s.config.DryRun { - fmt.Fprintf(&buf, ", %d with no output", noOutput) + fmt.Fprintf(&buf, ", %d with no output (hidden)", noOutput) } if noOutput != len(changes) { fmt.Fprintf(&buf, ":")