]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
changes: change dry-run messages to use "will"
authorSimon Ruderich <simon@ruderich.org>
Sun, 9 May 2021 10:44:29 +0000 (12:44 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sun, 9 May 2021 13:18:45 +0000 (15:18 +0200)
Don't suggest that the change already took place. "dry-run" is still
printed to make it clear why no changes were made.

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

index 0b54aeffc54d14dd72de424d9769b921df2548d0..8726307cba408a1002722bd2a7dc1e17d09ee524 100644 (file)
@@ -217,7 +217,7 @@ func TestSyncSshEndToEnd(t *testing.T) {
                        []string{"-n", "no-effect-commands.example.org"},
                        `<LOG>[info]    [no-effect-commands.example.org] remote helper upload in progress
 <LOG>[info]    [no-effect-commands.example.org] 
-executed 2 command(s): (dry-run)
+will execute 2 command(s): (dry-run)
 "echo this is a command"
 "true"
 `,
@@ -232,7 +232,7 @@ executed 2 command(s): (dry-run)
 <LOG>[verbose] [no-effect-commands.example.org] host groups: all <DET> <DET> no-effect-commands.example.org
 <LOG>[verbose] [no-effect-commands.example.org] host group priorities (descending): no-effect-commands.example.org
 <LOG>[info]    [no-effect-commands.example.org] 
-executed 2 command(s): (dry-run)
+will execute 2 command(s): (dry-run)
 "echo this is a command"
 "true"
 `,
@@ -280,7 +280,7 @@ executed 2 command(s):
                        []string{"-n", "no-effect-commands-failing.example.org"},
                        `<LOG>[info]    [no-effect-commands-failing.example.org] remote helper upload in progress
 <LOG>[info]    [no-effect-commands-failing.example.org] 
-executed 2 command(s): (dry-run)
+will execute 2 command(s): (dry-run)
 "echo this is a command"
 "echo failing; false"
 `,
@@ -295,7 +295,7 @@ executed 2 command(s): (dry-run)
 <LOG>[verbose] [no-effect-commands-failing.example.org] host groups: all <DET> <DET> no-effect-commands-failing.example.org
 <LOG>[verbose] [no-effect-commands-failing.example.org] host group priorities (descending): no-effect-commands-failing.example.org
 <LOG>[info]    [no-effect-commands-failing.example.org] 
-executed 2 command(s): (dry-run)
+will execute 2 command(s): (dry-run)
 "echo this is a command"
 "echo failing; false"
 `,
index 3e91768bfca3eb3273e5c24954c506f86934a63b..f597ae1a7fdc6b3532bbc1f15a22a3dae7ae2b4b 100644 (file)
@@ -66,11 +66,12 @@ func (s *Sync) formatChanges(resp safcm.MsgSyncResp) string {
 
 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))
 
@@ -116,7 +117,6 @@ func (s *Sync) formatFileChanges(changes []safcm.FileChange) string {
                }
                fmt.Fprintf(&buf, "\n")
        }
-
        return buf.String()
 }
 func formatFileType(info safcm.FileChangeInfo) string {
@@ -142,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))
@@ -156,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 {
@@ -197,7 +199,11 @@ 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)
        }
index febb7847edf600e43541294a81d8cd96864deaa5..feb8dd34531f007072b391fbc11b82b1e05d3a50 100644 (file)
@@ -125,7 +125,7 @@ func TestFormatChanges(t *testing.T) {
                                        },
                                },
                        },
-                       "\nexecuted 5 command(s): (dry-run)\n\"fake command\"\n\"fake command with no output\"\n\"fake command with newline\"\n\"fake command with more output\"\n\"fake failed command\"\n",
+                       "\nwill execute 5 command(s): (dry-run)\n\"fake command\"\n\"fake command with no output\"\n\"fake command with newline\"\n\"fake command with more output\"\n\"fake failed command\"\n",
                },
                {
                        "command changes only, quiet & dry-run",
@@ -151,7 +151,7 @@ func TestFormatChanges(t *testing.T) {
                                        },
                                },
                        },
-                       "executed 5 command(s) (dry-run)\n",
+                       "will execute 5 command(s) (dry-run)\n",
                },
        }
 
@@ -543,7 +543,7 @@ func TestFormatFileChanges(t *testing.T) {
                                        },
                                },
                        },
-                       `changed 1 file(s): (dry-run)
+                       `will change 1 file(s): (dry-run)
 "file": created, file, user(1000) group(2000), 0644
 `,
                },
@@ -565,7 +565,7 @@ func TestFormatFileChanges(t *testing.T) {
                                        },
                                },
                        },
-                       "changed 1 file(s): (dry-run)\n\x1B[36m\"file\"\x1B[0m: \x1B[32mcreated\x1B[0m, file, user(1000) group(2000), 0644\n",
+                       "will change 1 file(s): (dry-run)\n\x1B[36m\"file\"\x1B[0m: \x1B[32mcreated\x1B[0m, file, user(1000) group(2000), 0644\n",
                },
 
                {
@@ -723,7 +723,7 @@ func TestFormatPackageChanges(t *testing.T) {
                                        Name: "package-two",
                                },
                        },
-                       `installed 2 package(s): (dry-run)
+                       `will install 2 package(s): (dry-run)
 "package-one"
 "package-two"
 `,
@@ -741,7 +741,7 @@ func TestFormatPackageChanges(t *testing.T) {
                                        Name: "package-two",
                                },
                        },
-                       "installed 2 package(s): (dry-run)\n\x1b[36m\"package-one\"\x1b[0m\n\x1b[36m\"package-two\"\x1b[0m\n",
+                       "will install 2 package(s): (dry-run)\n\x1b[36m\"package-one\"\x1b[0m\n\x1b[36m\"package-two\"\x1b[0m\n",
                },
 
                {
@@ -862,7 +862,7 @@ func TestFormatServiceChanges(t *testing.T) {
                                        Enabled: true,
                                },
                        },
-                       `modified 3 service(s): (dry-run)
+                       `will modify 3 service(s): (dry-run)
 "service-one": started
 "service-two": enabled
 "service-three": started, enabled
@@ -888,7 +888,7 @@ func TestFormatServiceChanges(t *testing.T) {
                                        Enabled: true,
                                },
                        },
-                       "modified 3 service(s): (dry-run)\n\x1b[36m\"service-one\"\x1b[0m: started\n\x1b[36m\"service-two\"\x1b[0m: enabled\n\x1b[36m\"service-three\"\x1b[0m: started, enabled\n",
+                       "will modify 3 service(s): (dry-run)\n\x1b[36m\"service-one\"\x1b[0m: started\n\x1b[36m\"service-two\"\x1b[0m: enabled\n\x1b[36m\"service-three\"\x1b[0m: started, enabled\n",
                },
 
                {
@@ -1038,7 +1038,7 @@ func TestFormatCommandChanges(t *testing.T) {
                                        Command: "fake command",
                                },
                        },
-                       `executed 1 command(s): (dry-run)
+                       `will execute 1 command(s): (dry-run)
 "fake command"
 `,
                },
@@ -1053,7 +1053,7 @@ func TestFormatCommandChanges(t *testing.T) {
                                        Command: "fake command",
                                },
                        },
-                       "executed 1 command(s): (dry-run)\n\x1b[36m\"fake command\"\x1b[0m\n",
+                       "will execute 1 command(s): (dry-run)\n\x1b[36m\"fake command\"\x1b[0m\n",
                },
 
                {
@@ -1187,7 +1187,7 @@ func TestFormatCommandChanges(t *testing.T) {
                                        Command: "fake failed command",
                                },
                        },
-                       `executed 5 command(s) (dry-run)
+                       `will execute 5 command(s) (dry-run)
 `,
                },