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
parent
d897c94d29
commit
228ca6370e
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/haunt98/changeloguru/pkg/git"
|
"github.com/haunt98/changeloguru/pkg/git"
|
||||||
"github.com/haunt98/changeloguru/pkg/markdown"
|
"github.com/haunt98/changeloguru/pkg/markdown"
|
||||||
"github.com/pkg/diff"
|
"github.com/pkg/diff"
|
||||||
|
"github.com/pkg/diff/write"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
)
|
)
|
||||||
|
@ -114,17 +115,13 @@ func (a *action) generateMarkdownChangelog(output, version string, commits []con
|
||||||
// Generate markdown from commits
|
// Generate markdown from commits
|
||||||
newNodes := changelog.GenerateMarkdown(commits, a.flags.scopes, version, time.Now())
|
newNodes := changelog.GenerateMarkdown(commits, a.flags.scopes, version, time.Now())
|
||||||
|
|
||||||
// Final changelog
|
// Final changelog with new commits above old commits
|
||||||
nodes := append(newNodes, oldNodes...)
|
nodes := append(newNodes, oldNodes...)
|
||||||
changelogText := markdown.GenerateText(nodes)
|
changelogText := markdown.GenerateText(nodes)
|
||||||
|
|
||||||
// Demo run
|
// Demo run
|
||||||
if a.flags.dryRun {
|
if a.flags.dryRun {
|
||||||
oldLines := strings.Split(string(bytes), string(markdown.NewlineToken))
|
if err := diff.Text("old", "new", string(bytes), changelogText, os.Stdout, write.TerminalColor()); err != nil {
|
||||||
newLines := strings.Split(changelogText, string(markdown.NewlineToken))
|
|
||||||
if err := diff.Slices("old", "new",
|
|
||||||
oldLines, newLines,
|
|
||||||
os.Stdout); err != nil {
|
|
||||||
return fmt.Errorf("failed to diff old and new changelog: %w", err)
|
return fmt.Errorf("failed to diff old and new changelog: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue