Skip to content

Commit

Permalink
Merge pull request #116 from x-motemen/fetch
Browse files Browse the repository at this point in the history
add fetch subcommand
  • Loading branch information
Songmu committed Oct 28, 2023
2 parents 7880ee2 + e6d4571 commit 777baca
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func main() {
app := cli.NewApp()
app.Commands = []*cli.Command{
commandPull,
commandFetch,
commandPush,
commandPost,
commandList,
Expand Down Expand Up @@ -133,6 +134,48 @@ var commandPull = &cli.Command{
},
}

var commandFetch = &cli.Command{
Name: "fetch",
Usage: "Fetch entries from remote",
Action: func(c *cli.Context) error {
first := c.Args().First()
if first == "" {
cli.ShowCommandHelp(c, "fetch")
return errCommandHelp
}
conf, err := loadConfiguration()
if err != nil {
return err
}
for _, path := range c.Args().Slice() {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()

e, err := entryFromReader(f)
if err != nil {
return err
}
blogID, err := e.blogID()
if err != nil {
return err
}

bc := conf.Get(blogID)
if bc == nil {
return fmt.Errorf("cannot find blog for %s", path)
}
b := newBroker(bc)
if _, err := b.StoreFresh(e, path); err != nil {
return err
}
}
return nil
},
}

var commandPush = &cli.Command{
Name: "push",
Usage: "Push local entries to remote",
Expand Down

0 comments on commit 777baca

Please sign in to comment.