Skip to content

Commit

Permalink
Merge pull request #110 from x-motemen/without-draft
Browse files Browse the repository at this point in the history
add "--no-drafts" and "--only-drafts" flags to pull subcommand for drafts management
  • Loading branch information
Songmu committed Oct 22, 2023
2 parents 5fe10ba + 9b95420 commit 3174648
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newBroker(bc *blogConfig) *broker {
}
}

func (b *broker) FetchRemoteEntries() ([]*entry, error) {
func (b *broker) FetchRemoteEntries(published, drafts bool) ([]*entry, error) {
entries := []*entry{}
fixedPageURL := fixedPageEndpointURL(b.blogConfig)
urls := []string{
Expand Down Expand Up @@ -63,7 +63,9 @@ func (b *broker) FetchRemoteEntries() ([]*entry, error) {
if err != nil {
return nil, err
}
entries = append(entries, e)
if (e.IsDraft && drafts) || (!e.IsDraft && published) {
entries = append(entries, e)
}
}

nextLink := feed.Links.Find("next")
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func loadConfigFiles(pwd string) (*config, error) {
var commandPull = &cli.Command{
Name: "pull",
Usage: "Pull entries from remote",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "no-drafts"},
&cli.BoolFlag{Name: "only-drafts"},
},
Action: func(c *cli.Context) error {
blog := c.Args().First()
if blog == "" {
Expand All @@ -112,7 +116,8 @@ var commandPull = &cli.Command{
}

b := newBroker(blogConfig)
remoteEntries, err := b.FetchRemoteEntries()
remoteEntries, err := b.FetchRemoteEntries(
!c.Bool("only-drafts"), !c.Bool("no-drafts"))
if err != nil {
return err
}
Expand Down

0 comments on commit 3174648

Please sign in to comment.