Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fetch subcommand #116

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading