X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fsync_changes.go;h=3e91768bfca3eb3273e5c24954c506f86934a63b;hb=367edc1286a52d96fcfef6f98330148cad8a64e1;hp=1ec3cb60b435632fedac3e95b975239d1f12160e;hpb=ccde6eed234a8530c8180264937566ca5d092bdc;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/sync_changes.go b/cmd/safcm/sync_changes.go index 1ec3cb6..3e91768 100644 --- a/cmd/safcm/sync_changes.go +++ b/cmd/safcm/sync_changes.go @@ -49,9 +49,19 @@ 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 { @@ -176,7 +186,7 @@ func (s *Sync) formatCommandChanges(changes []safcm.CommandChange) string { // Instead, quiet shows them only when they produce output (e.g. // `ainsl`, `rm -v`) and thus modify the host's state. var noOutput int - if s.config.Quiet && !s.config.DryRun { + if s.config.Quiet { for _, x := range changes { if x.Trigger == "" && x.Error == "" && @@ -188,7 +198,7 @@ func (s *Sync) formatCommandChanges(changes []safcm.CommandChange) string { var buf strings.Builder fmt.Fprintf(&buf, "executed %d command(s)", len(changes)) - if noOutput > 0 { + if noOutput > 0 && !s.config.DryRun { fmt.Fprintf(&buf, ", %d with no output", noOutput) } if noOutput != len(changes) {