From 228ca6370e2bf4c35767700655b94d6d5b2939bb Mon Sep 17 00:00:00 2001 From: Nguyen Tran Hau Date: Fri, 23 Apr 2021 10:36:10 +0700 Subject: [PATCH] feat: add color to dry run (#14) * feat: add color to dry run mode * chore: better wording Co-authored-by: Tran Hau --- pkg/cli/action_generate.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/cli/action_generate.go b/pkg/cli/action_generate.go index 997056a..b7f8e1b 100644 --- a/pkg/cli/action_generate.go +++ b/pkg/cli/action_generate.go @@ -12,6 +12,7 @@ import ( "github.com/haunt98/changeloguru/pkg/git" "github.com/haunt98/changeloguru/pkg/markdown" "github.com/pkg/diff" + "github.com/pkg/diff/write" "github.com/urfave/cli/v2" "golang.org/x/mod/semver" ) @@ -114,17 +115,13 @@ func (a *action) generateMarkdownChangelog(output, version string, commits []con // Generate markdown from commits newNodes := changelog.GenerateMarkdown(commits, a.flags.scopes, version, time.Now()) - // Final changelog + // Final changelog with new commits above old commits nodes := append(newNodes, oldNodes...) changelogText := markdown.GenerateText(nodes) // Demo run if a.flags.dryRun { - oldLines := strings.Split(string(bytes), string(markdown.NewlineToken)) - newLines := strings.Split(changelogText, string(markdown.NewlineToken)) - if err := diff.Slices("old", "new", - oldLines, newLines, - os.Stdout); err != nil { + if err := diff.Text("old", "new", string(bytes), changelogText, os.Stdout, write.TerminalColor()); err != nil { return fmt.Errorf("failed to diff old and new changelog: %w", err) }