From: Simon Ruderich Date: Sat, 10 Apr 2021 18:16:06 +0000 (+0200) Subject: changes: hide commands if quiet and dry-run is active X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;ds=sidebyside;h=cfcc39441d8e9b1f003b8d5c02240e7186bfc2d1;p=safcm%2Fsafcm.git changes: hide commands if quiet and dry-run is active The goal of quiet is to get a quick overview what is happening or what is going to happen (when combined with dry-run). While quiet worked fine for non dry-run syncs it was not very helpful for dry-runs. This change makes the output much more compact and readable with many commands and hosts. --- diff --git a/cmd/safcm/sync_changes.go b/cmd/safcm/sync_changes.go index 1ec3cb6..6327fd9 100644 --- a/cmd/safcm/sync_changes.go +++ b/cmd/safcm/sync_changes.go @@ -176,7 +176,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 +188,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) { diff --git a/cmd/safcm/sync_changes_test.go b/cmd/safcm/sync_changes_test.go index 9326dbb..c1e4aef 100644 --- a/cmd/safcm/sync_changes_test.go +++ b/cmd/safcm/sync_changes_test.go @@ -1134,12 +1134,7 @@ func TestFormatCommandChanges(t *testing.T) { Command: "fake failed command", }, }, - `executed 5 command(s): (dry-run) -"fake command" -"fake command with no output" -"fake command with newline" -"fake command with more output" -"fake failed command" + `executed 5 command(s) (dry-run) `, },