Skip to content

Commit

Permalink
chore: Print document separators between errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 24, 2024
1 parent 5f76006 commit 3960864
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@ func walkPaths(cmd *cobra.Command, conf *config.Config, args []string) error {
conf.NoSourceComment = len(args) <= 1 && !hasDir
}

var i int
var printSeparator bool
var errs []error
for _, arg := range args {
if err := filepath.WalkDir(arg, func(path string, d fs.DirEntry, err error) error {
if err != nil {
if logErrors {
slog.Error("Failed to template file", "error", err)
printSeparator = true
}
errs = append(errs, err)
return nil
Expand All @@ -127,19 +128,20 @@ func walkPaths(cmd *cobra.Command, conf *config.Config, args []string) error {
return nil
}

if !conf.Inplace && i != 0 {
if printSeparator && !conf.Inplace {
printSeparator = false
if _, err := io.WriteString(cmd.OutOrStdout(), "---\n"); err != nil {
return err
}
}
i++

if err := openAndTemplateFile(conf, cmd.OutOrStdout(), path); err != nil {
if logErrors {
slog.Error("Failed to template file", "error", err)
}
errs = append(errs, err)
}
printSeparator = true
return nil
}); err != nil {
return err
Expand Down

0 comments on commit 3960864

Please sign in to comment.