Skip to content

Commit

Permalink
maint/polish ~ whitespace fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
rivy committed Feb 14, 2021
1 parent 530970c commit dde4272
Show file tree
Hide file tree
Showing 56 changed files with 4,363 additions and 4,363 deletions.
2 changes: 1 addition & 1 deletion cmd/git-changelog/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package main

// Builder ...
type Builder interface {
Build(*Answer) (string, error)
Build(*Answer) (string, error)
}
200 changes: 100 additions & 100 deletions cmd/git-changelog/cli.go
Original file line number Diff line number Diff line change
@@ -1,133 +1,133 @@
package main

import (
"fmt"
"io"
"path/filepath"
"time"
"fmt"
"io"
"path/filepath"
"time"

"github.com/fatih/color"
"github.com/fatih/color"

changelog "github.com/rivy-go/git-changelog/internal/changelog"
changelog "github.com/rivy-go/git-changelog/internal/changelog"
)

// CLI ...
type CLI struct {
ctx *CLIContext
fs FileSystem
logger *Logger
configLoader ConfigLoader
generator Generator
processorFactory *ProcessorFactory
ctx *CLIContext
fs FileSystem
logger *Logger
configLoader ConfigLoader
generator Generator
processorFactory *ProcessorFactory
}

// NewCLI ...
func NewCLI(
ctx *CLIContext, fs FileSystem,
configLoader ConfigLoader,
generator Generator,
ctx *CLIContext, fs FileSystem,
configLoader ConfigLoader,
generator Generator,
) *CLI {
silent := false
if ctx.Silent || ctx.OutputPath == "" {
silent = true
}

return &CLI{
ctx: ctx,
fs: fs,
logger: NewLogger(ctx.Stdout, ctx.Stderr, silent, ctx.NoEmoji),
configLoader: configLoader,
generator: generator,
processorFactory: NewProcessorFactory(),
}
silent := false
if ctx.Silent || ctx.OutputPath == "" {
silent = true
}

return &CLI{
ctx: ctx,
fs: fs,
logger: NewLogger(ctx.Stdout, ctx.Stderr, silent, ctx.NoEmoji),
configLoader: configLoader,
generator: generator,
processorFactory: NewProcessorFactory(),
}
}

// Run ...
func (c *CLI) Run() int {
start := time.Now()

if c.ctx.NoColor {
color.NoColor = true
}

c.logger.Log(":watch: Generating changelog ...")

config, err := c.prepareConfig()
if err != nil {
c.logger.Error(err.Error())
return ExitCodeError
}

changelogConfig, err := c.createChangelogConfig(config)
if err != nil {
c.logger.Error(err.Error())
return ExitCodeError
}

w, err := c.createOutputWriter()
if err != nil {
c.logger.Error(err.Error())
return ExitCodeError
}

err = c.generator.Generate(w, c.ctx.Query, changelogConfig)
if err != nil {
c.logger.Error(err.Error())
return ExitCodeError
}

c.logger.Log(fmt.Sprintf(":sparkles: Generate of %s is completed! (%s)",
color.GreenString("\""+c.ctx.OutputPath+"\""),
color.New(color.Bold).SprintFunc()(time.Since(start).String()),
))

return ExitCodeOK
start := time.Now()

if c.ctx.NoColor {
color.NoColor = true
}

c.logger.Log(":watch: Generating changelog ...")

config, err := c.prepareConfig()
if err != nil {
c.logger.Error(err.Error())
return ExitCodeError
}

changelogConfig, err := c.createChangelogConfig(config)
if err != nil {
c.logger.Error(err.Error())
return ExitCodeError
}

w, err := c.createOutputWriter()
if err != nil {
c.logger.Error(err.Error())
return ExitCodeError
}

err = c.generator.Generate(w, c.ctx.Query, changelogConfig)
if err != nil {
c.logger.Error(err.Error())
return ExitCodeError
}

c.logger.Log(fmt.Sprintf(":sparkles: Generate of %s is completed! (%s)",
color.GreenString("\""+c.ctx.OutputPath+"\""),
color.New(color.Bold).SprintFunc()(time.Since(start).String()),
))

return ExitCodeOK
}

func (c *CLI) prepareConfig() (*Config, error) {
config, err := c.configLoader.Load(c.ctx.ConfigPath)
if err != nil {
return nil, err
}
config, err := c.configLoader.Load(c.ctx.ConfigPath)
if err != nil {
return nil, err
}

err = config.Normalize(c.ctx)
if err != nil {
return nil, err
}
err = config.Normalize(c.ctx)
if err != nil {
return nil, err
}

config.Convert(c.ctx)
config.Convert(c.ctx)

return config, err
return config, err
}

func (c *CLI) createChangelogConfig(config *Config) (*changelog.Config, error) {
processor, err := c.processorFactory.Create(config)
if err != nil {
return nil, err
}
processor, err := c.processorFactory.Create(config)
if err != nil {
return nil, err
}

changelogConfig := config.Convert(c.ctx)
changelogConfig.Options.Processor = processor
changelogConfig := config.Convert(c.ctx)
changelogConfig.Options.Processor = processor

return changelogConfig, nil
return changelogConfig, nil
}

func (c *CLI) createOutputWriter() (io.Writer, error) {
if c.ctx.OutputPath == "" {
return c.ctx.Stdout, nil
}

out := c.ctx.OutputPath
dir := filepath.Dir(out)
err := c.fs.MkdirP(dir)
if err != nil {
return nil, err
}

file, err := c.fs.Create(out)
if err != nil {
return nil, err
}

return file, nil
if c.ctx.OutputPath == "" {
return c.ctx.Stdout, nil
}

out := c.ctx.OutputPath
dir := filepath.Dir(out)
err := c.fs.MkdirP(dir)
if err != nil {
return nil, err
}

file, err := c.fs.Create(out)
if err != nil {
return nil, err
}

return file, nil
}
Loading

0 comments on commit dde4272

Please sign in to comment.