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

claim posts #34

Merged
merged 4 commits into from Jun 11, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

Tweak post claim logging

- Presents a summary before making the request when verbose (-v) enabled
- Successful claims only shown with verbose (-v) enabled
- Failed claims now always mention cause of failure
- A summary of successes / failures shows after logging any failures,
  when verbose (-v) enabled

Ref T194
  • Loading branch information...
thebaer committed Jun 11, 2019
commit ed5e498c40445bc4bc8e0077da60e6000253fe51
@@ -184,6 +184,12 @@ func main() {
Usage: "Claim local unsynced posts",
Action: commands.CmdClaim,
Description: "This will claim any unsynced posts local to this machine. To see which posts these are run: writeas posts.",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "verbose, v",
Usage: "Make the operation more talkative",
},
},
},
{
Name: "auth",
@@ -293,29 +293,31 @@ func CmdClaim(c *cli.Context) error {
return nil
}

log.Info(c, "Claiming %d post(s) for %s...", len(*localPosts), u.User.Username)
results, err := api.ClaimPosts(c, localPosts)
if err != nil {
return cli.NewExitError(fmt.Sprintf("Failed to claim posts: %v", err), 1)
}

var okCount, errCount int
for _, r := range *results {
id := r.ID
if id == "" {
// No top-level ID, so the claim was successful
id = r.Post.ID
}
fmt.Printf("Adding %s to user %s..", id, u.User.Username)
status := fmt.Sprintf("Post %s...", id)
if r.ErrorMessage != "" {
fmt.Printf(" Failed\n")
if config.Debug() {
log.Errorln("Failed claiming post %s: %v", id, r.ErrorMessage)
}
log.Errorln("%serror: %v", status, r.ErrorMessage)
errCount++
} else {
fmt.Printf(" OK\n")
log.Info(c, "%sOK", status)
okCount++
// only delete local if successful
api.RemovePost(c.App.ExtraInfo()["configDir"], id)
}
}
log.Info(c, "%d claimed, %d failed", okCount, errCount)
return nil
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.