]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
changes: hide commands if quiet and dry-run is active
authorSimon Ruderich <simon@ruderich.org>
Sat, 10 Apr 2021 18:16:06 +0000 (20:16 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sat, 10 Apr 2021 18:16:06 +0000 (20:16 +0200)
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.

cmd/safcm/sync_changes.go
cmd/safcm/sync_changes_test.go

index 1ec3cb60b435632fedac3e95b975239d1f12160e..6327fd9addbaec497a31452a635082cb6f65b32e 100644 (file)
@@ -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
        // 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 == "" &&
                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))
 
        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) {
                fmt.Fprintf(&buf, ", %d with no output", noOutput)
        }
        if noOutput != len(changes) {
index 9326dbbf3e6638120d9cdbcfc5237a5e241265e0..c1e4aef899e257eeef2cb832282b6cca9b29770a 100644 (file)
@@ -1134,12 +1134,7 @@ func TestFormatCommandChanges(t *testing.T) {
                                        Command: "fake failed command",
                                },
                        },
                                        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)
 `,
                },
 
 `,
                },