Skip to content

Commit

Permalink
use c.App.Writer properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Nov 3, 2023
1 parent 40d7c1e commit bbc5172
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
7 changes: 5 additions & 2 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ type broker struct {
writer io.Writer
}

func newBroker(bc *blogConfig) *broker {
func newBroker(bc *blogConfig, w io.Writer) *broker {
if w == nil {
w = os.Stdout
}
return &broker{
Client: &atom.Client{
Client: &http.Client{
Expand All @@ -28,7 +31,7 @@ func newBroker(bc *blogConfig) *broker {
},
},
blogConfig: bc,
writer: os.Stdout,
writer: w,
}
}

Expand Down
2 changes: 1 addition & 1 deletion broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestOriginalPath(t *testing.T) {
BlogID: "example1.hatenablog.com",
Username: "sample1",
}
broker := newBroker(&config)
broker := newBroker(&config, nil)

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (bc *blogConfig) fetchRootURL() string {
if bc.rootURL != "" {
return bc.rootURL
}
b := newBroker(bc)
b := newBroker(bc, nil)
u := entryEndPointUrl(bc)
feed, err := b.Client.GetFeed(u)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var commandPull = &cli.Command{
return fmt.Errorf("blog not found: %s", blog)
}

b := newBroker(blogConfig)
b := newBroker(blogConfig, c.App.Writer)
remoteEntries, err := b.FetchRemoteEntries(
!c.Bool("only-drafts"), !c.Bool("no-drafts"))
if err != nil {
Expand Down Expand Up @@ -177,7 +177,7 @@ var commandFetch = &cli.Command{
if bc == nil {
return fmt.Errorf("cannot find blog for %s", path)
}
b := newBroker(bc)
b := newBroker(bc, c.App.Writer)
if _, err := b.StoreFresh(e, path); err != nil {
return err
}
Expand Down Expand Up @@ -236,7 +236,7 @@ var commandPush = &cli.Command{
return fmt.Errorf("%q is not a blog entry", path)
}
entry.CustomPath = strings.TrimSuffix(stuffs[1], entryExt)
b := newBroker(bc)
b := newBroker(bc, c.App.Writer)
err = b.PostEntry(entry, false)
if err != nil {
return err
Expand All @@ -253,7 +253,7 @@ var commandPush = &cli.Command{
return fmt.Errorf("cannot find blog for %s", path)
}

_, err = newBroker(bc).UploadFresh(entry)
_, err = newBroker(bc, c.App.Writer).UploadFresh(entry)
if err != nil {
return err
}
Expand Down Expand Up @@ -304,7 +304,7 @@ var commandPost = &cli.Command{
entry.Title = title
}

b := newBroker(blogConfig)
b := newBroker(blogConfig, c.App.Writer)
err = b.PostEntry(entry, c.Bool("page"))
if err != nil {
return err
Expand Down Expand Up @@ -389,7 +389,7 @@ var commandRemove = &cli.Command{
return fmt.Errorf("cannot find blog for %s", path)
}

err = newBroker(bc).RemoveEntry(entry, path)
err = newBroker(bc, c.App.Writer).RemoveEntry(entry, path)
if err != nil {
return err
}
Expand Down

0 comments on commit bbc5172

Please sign in to comment.