summaryrefslogtreecommitdiff
path: root/vendor/github.com/google/yamlfmt/engine
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/google/yamlfmt/engine')
-rw-r--r--vendor/github.com/google/yamlfmt/engine/consecutive_engine.go21
-rw-r--r--vendor/github.com/google/yamlfmt/engine/output.go16
2 files changed, 30 insertions, 7 deletions
diff --git a/vendor/github.com/google/yamlfmt/engine/consecutive_engine.go b/vendor/github.com/google/yamlfmt/engine/consecutive_engine.go
index 650d1b7..1ec241a 100644
--- a/vendor/github.com/google/yamlfmt/engine/consecutive_engine.go
+++ b/vendor/github.com/google/yamlfmt/engine/consecutive_engine.go
@@ -19,15 +19,17 @@ import (
"os"
"github.com/google/yamlfmt"
+ "github.com/google/yamlfmt/internal/logger"
)
// Engine that will process each file one by one consecutively.
type ConsecutiveEngine struct {
LineSepCharacter string
Formatter yamlfmt.Formatter
- Quiet bool
ContinueOnError bool
OutputFormat EngineOutputFormat
+ Quiet bool
+ Verbose bool
}
func (e *ConsecutiveEngine) FormatContent(content []byte) ([]byte, error) {
@@ -36,6 +38,13 @@ func (e *ConsecutiveEngine) FormatContent(content []byte) ([]byte, error) {
func (e *ConsecutiveEngine) Format(paths []string) (fmt.Stringer, error) {
formatDiffs, formatErrs := e.formatAll(paths)
+
+ // Debug format diff output.
+ logger.Debug(
+ logger.DebugCodeDiffs,
+ fmt.Sprintf("The following files were modified:\n%s", formatDiffs.StrOutput()),
+ )
+
if len(formatErrs) > 0 {
if e.ContinueOnError {
fmt.Print(formatErrs)
@@ -44,7 +53,11 @@ func (e *ConsecutiveEngine) Format(paths []string) (fmt.Stringer, error) {
return nil, formatErrs
}
}
- return nil, formatDiffs.ApplyAll()
+ applyErr := formatDiffs.ApplyAll()
+ if applyErr != nil {
+ return nil, applyErr
+ }
+ return getEngineOutput(e.OutputFormat, yamlfmt.OperationFormat, formatDiffs, e.Quiet, e.Verbose)
}
func (e *ConsecutiveEngine) Lint(paths []string) (fmt.Stringer, error) {
@@ -55,7 +68,7 @@ func (e *ConsecutiveEngine) Lint(paths []string) (fmt.Stringer, error) {
if formatDiffs.ChangedCount() == 0 {
return nil, nil
}
- return getEngineOutput(e.OutputFormat, yamlfmt.OperationLint, formatDiffs, e.Quiet)
+ return getEngineOutput(e.OutputFormat, yamlfmt.OperationLint, formatDiffs, e.Quiet, e.Verbose)
}
func (e *ConsecutiveEngine) DryRun(paths []string) (fmt.Stringer, error) {
@@ -66,7 +79,7 @@ func (e *ConsecutiveEngine) DryRun(paths []string) (fmt.Stringer, error) {
if formatDiffs.ChangedCount() == 0 {
return nil, nil
}
- return getEngineOutput(e.OutputFormat, yamlfmt.OperationDry, formatDiffs, e.Quiet)
+ return getEngineOutput(e.OutputFormat, yamlfmt.OperationDry, formatDiffs, e.Quiet, e.Verbose)
}
func (e *ConsecutiveEngine) formatAll(paths []string) (yamlfmt.FileDiffs, FormatErrors) {
diff --git a/vendor/github.com/google/yamlfmt/engine/output.go b/vendor/github.com/google/yamlfmt/engine/output.go
index 2d35e84..c6a2e9e 100644
--- a/vendor/github.com/google/yamlfmt/engine/output.go
+++ b/vendor/github.com/google/yamlfmt/engine/output.go
@@ -32,10 +32,10 @@ const (
EngineOutputGitlab EngineOutputFormat = "gitlab"
)
-func getEngineOutput(t EngineOutputFormat, operation yamlfmt.Operation, files yamlfmt.FileDiffs, quiet bool) (fmt.Stringer, error) {
+func getEngineOutput(t EngineOutputFormat, operation yamlfmt.Operation, files yamlfmt.FileDiffs, quiet bool, verbose bool) (fmt.Stringer, error) {
switch t {
case EngineOutputDefault:
- return engineOutput{Operation: operation, Files: files, Quiet: quiet}, nil
+ return engineOutput{Operation: operation, Files: files, Quiet: quiet, Verbose: verbose}, nil
case EngineOutputSingeLine:
return engineOutputSingleLine{Operation: operation, Files: files, Quiet: quiet}, nil
case EngineOutputGitlab:
@@ -49,11 +49,21 @@ type engineOutput struct {
Operation yamlfmt.Operation
Files yamlfmt.FileDiffs
Quiet bool
+ Verbose bool
}
func (eo engineOutput) String() string {
var msg string
switch eo.Operation {
+ case yamlfmt.OperationFormat:
+ // Formatting only produces output in verbose mode.
+ if !eo.Verbose {
+ return ""
+ }
+
+ msg = "The following files were modified:\n"
+ msg += eo.Files.StrOutputQuiet()
+ return msg
case yamlfmt.OperationLint:
msg = "The following formatting differences were found:"
if eo.Quiet {
@@ -65,7 +75,7 @@ func (eo engineOutput) String() string {
msg = "The following files would be formatted:"
}
} else {
- return "No files will formatted."
+ return "No files will be formatted."
}
}
var result string