feat: add color to dry run (#14)

* feat: add color to dry run mode

* chore: better wording

Co-authored-by: Tran Hau <ngtranhau@gmail.com>
main
sudo pacman -Syu 2021-04-23 10:36:10 +07:00 committed by GitHub
parent d897c94d29
commit 228ca6370e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

@ -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)
}