Skip to content

Commit

Permalink
engine: return nil from dry run when no changes
Browse files Browse the repository at this point in the history
The `command` output actually relies on `nil` being return when there
are no changes, and I forgot to add that behaviour to dry run which made
there be no message printed out for confirmation.

Also decided to make a slight change to the confirmation message so that
it outputs nothing when the `-quiet` flag is enabled.

Signed-off-by: braydonk <braydonk@google.com>
  • Loading branch information
braydonk committed May 3, 2024
1 parent fc5b1e4 commit f51e552
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func (c *Command) Run() error {
}
if out != nil {
fmt.Print(out)
} else {
fmt.Print("No files will be changed.")
} else if !c.Quiet {
fmt.Println("No files will be changed.")
}
case yamlfmt.OperationStdin:
stdinYaml, err := readFromStdin()
Expand Down
3 changes: 3 additions & 0 deletions engine/consecutive_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func (e *ConsecutiveEngine) DryRun(paths []string) (fmt.Stringer, error) {
if len(formatErrs) > 0 {
return nil, formatErrs
}
if formatDiffs.ChangedCount() == 0 {
return nil, nil
}
return getEngineOutput(e.OutputFormat, yamlfmt.OperationDry, formatDiffs, e.Quiet)
}

Expand Down

0 comments on commit f51e552

Please sign in to comment.