Skip to content

Commit

Permalink
Avoid extra buffer in commands
Browse files Browse the repository at this point in the history
No need to use `bytes.Buffer` since we moved to
`buffio` package.
  • Loading branch information
rcmachado committed Jan 6, 2020
1 parent 2461870 commit d54c80c
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 28 deletions.
7 changes: 1 addition & 6 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"bufio"
"bytes"
"fmt"
"log"
"os"
Expand All @@ -23,11 +22,7 @@ var bundleCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
changelog := parser.Parse(inputFile)
bundleFiles(directory, changelog)

var buf bytes.Buffer
changelog.Render(&buf)

outputFile.ReadFrom(&buf)
changelog.Render(outputFile)
},
}

Expand Down
7 changes: 1 addition & 6 deletions cmd/commands.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"bytes"
"fmt"
"strings"

Expand All @@ -24,11 +23,7 @@ func buildCommands(rootCmd *cobra.Command) {
Run: func(cmd *cobra.Command, args []string) {
changelog := parser.Parse(inputFile)
changelog.AddItem(cmdType, strings.Join(args, " "))

var buf bytes.Buffer
changelog.Render(&buf)

outputFile.ReadFrom(&buf)
changelog.Render(outputFile)
},
}

Expand Down
8 changes: 1 addition & 7 deletions cmd/fmt.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cmd

import (
"bytes"

"github.com/rcmachado/changelog/parser"
"github.com/spf13/cobra"
)
Expand All @@ -13,11 +11,7 @@ var fmtCmd = &cobra.Command{
Long: "Reformats changelog input following keepachangelog.com spec",
Run: func(cmd *cobra.Command, args []string) {
changelog := parser.Parse(inputFile)

var buf bytes.Buffer
changelog.Render(&buf)

outputFile.ReadFrom(&buf)
changelog.Render(outputFile)
},
}

Expand Down
5 changes: 1 addition & 4 deletions cmd/release.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"bytes"
"fmt"
"io"
"os"
Expand All @@ -25,9 +24,7 @@ It will normalize the output with the new version.
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var buf bytes.Buffer
release(inputFile, args, &buf)
outputFile.ReadFrom(&buf)
release(inputFile, args, outputFile)
},
}

Expand Down
6 changes: 1 addition & 5 deletions cmd/show.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"bytes"
"fmt"
"os"

Expand All @@ -23,10 +22,7 @@ var showCmd = &cobra.Command{
os.Exit(3)
}

var buf bytes.Buffer
v.RenderChanges(&buf)

outputFile.ReadFrom(&buf)
v.RenderChanges(outputFile)
},
}

Expand Down

0 comments on commit d54c80c

Please sign in to comment.