Skip to content

Commit

Permalink
make the blogID argument of blogsync pull optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Oct 29, 2023
1 parent 936e2ad commit ec977d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
10 changes: 10 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func (c *config) detectBlogConfig(fpath string) *blogConfig {
return retBc
}

func (c *config) localBlogIDs() []string {
var ret []string
for blogID, bc := range c.Blogs {
if bc.local {
ret = append(ret, blogID)
}
}
return ret
}

type blogConfig struct {
BlogID string `yaml:"-"`
LocalRoot string `yaml:"local_root"`
Expand Down
42 changes: 24 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,40 @@ var commandPull = &cli.Command{
&cli.BoolFlag{Name: "only-drafts"},
},
Action: func(c *cli.Context) error {
blog := c.Args().First()
if blog == "" {
cli.ShowCommandHelp(c, "pull")
return errCommandHelp
}

conf, err := loadConfiguration()
if err != nil {
return err
}
blogConfig := conf.Get(blog)
if blogConfig == nil {
return fmt.Errorf("blog not found: %s", blog)
}

b := newBroker(blogConfig)
remoteEntries, err := b.FetchRemoteEntries(
!c.Bool("only-drafts"), !c.Bool("no-drafts"))
if err != nil {
return err
blogs := c.Args().Slice()
if len(blogs) == 0 {
blogs = conf.localBlogIDs()
}
if len(blogs) == 0 {
cli.ShowCommandHelp(c, "pull")
return errCommandHelp
}

for _, re := range remoteEntries {
path := b.LocalPath(re)
_, err := b.StoreFresh(re, path)
for _, blog := range blogs {
blogConfig := conf.Get(blog)
if blogConfig == nil {
return fmt.Errorf("blog not found: %s", blog)
}

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

for _, re := range remoteEntries {
path := b.LocalPath(re)
_, err := b.StoreFresh(re, path)
if err != nil {
return err
}
}
}
return nil
},
Expand Down

0 comments on commit ec977d2

Please sign in to comment.