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 {
// 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 == "" &&
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) {