Bläddra i källkod

Merge pull request #40 from writeas/revert-post-list

revert posts listing style to v1.2
pull/41/head
Matt Baer 4 år sedan
committed by GitHub
förälder
incheckning
f1947e48e2
Ingen känd nyckel hittad för denna signaturen i databasen GPG-nyckel ID: 4AEE18F83AFDEB23
3 ändrade filer med 41 tillägg och 45 borttagningar
  1. +11
    -6
      GUIDE.md
  2. +5
    -1
      cmd/writeas/main.go
  3. +25
    -38
      commands/commands.go

+ 11
- 6
GUIDE.md Visa fil

@@ -84,19 +84,24 @@ user An Example Blog
dev My Dev Log dev My Dev Log
``` ```


#### List all published posts
#### List posts


This lists all posts you've published from your device, as well as any published by the authenticated user.
This lists all posts you've published from your device


Pass the `--url` flag to show the list with full post URLs, and the `--md` flag to return URLs with Markdown enabled. Pass the `--url` flag to show the list with full post URLs, and the `--md` flag to return URLs with Markdown enabled.


To see post IDs with their Edit Tokens pass the `--v` flag.

```bash ```bash
$ writeas posts $ writeas posts
Local ID Token
unsynced aaaazzzzzzzza dhuieoj23894jhf984hdfs9834hdf84j
aaaazzzzzzzza

$ writeas posts -url
https://write.as/aaaazzzzzzzza


Account ID Title
synced mmmmmmmm33333333 This is a post
$ writeas posts -v
ID Token
aaaazzzzzzzza dhuieoj23894jhf984hdfs9834hdf84j
``` ```


#### Delete a post #### Delete a post


+ 5
- 1
cmd/writeas/main.go Visa fil

@@ -153,7 +153,7 @@ func main() {
{ {
Name: "posts", Name: "posts",
Usage: "List all of your posts", Usage: "List all of your posts",
Description: "This will list only local posts when not currently authenticated. To list remote posts as well, first run: writeas auth <username>.",
Description: "This will list only local posts.",
Action: commands.CmdListPosts, Action: commands.CmdListPosts,
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.BoolFlag{ cli.BoolFlag{
@@ -168,6 +168,10 @@ func main() {
Name: "url", Name: "url",
Usage: "Show list with URLs", Usage: "Show list with URLs",
}, },
cli.BoolFlag{
Name: "verbose, v",
Usage: "Show verbose post listing, including Edit Tokens",
},
}, },
}, { }, {
Name: "blogs", Name: "blogs",


+ 25
- 38
commands/commands.go Visa fil

@@ -166,53 +166,40 @@ func CmdAdd(c *cli.Context) error {
func CmdListPosts(c *cli.Context) error { func CmdListPosts(c *cli.Context) error {
urls := c.Bool("url") urls := c.Bool("url")
ids := c.Bool("id") ids := c.Bool("id")
details := c.Bool("v")


var p api.Post
posts := api.GetPosts(c) posts := api.GetPosts(c)
tw := tabwriter.NewWriter(os.Stdout, 10, 0, 2, ' ', tabwriter.TabIndent)
numPosts := len(*posts)
if ids || !urls && numPosts != 0 {
fmt.Fprintf(tw, "Local\t%s\t%s\t\n", "ID", "Token")
} else if numPosts != 0 {
fmt.Fprintf(tw, "Local\t%s\t%s\t\n", "URL", "Token")
} else {
fmt.Fprintf(tw, "No local posts found\n")
}
for i := range *posts {
p = (*posts)[numPosts-1-i]
if ids || !urls {
fmt.Fprintf(tw, "unsynced\t%s\t%s\t\n", p.ID, p.EditToken)

if details {
var p api.Post
tw := tabwriter.NewWriter(os.Stdout, 10, 0, 2, ' ', tabwriter.TabIndent)
numPosts := len(*posts)
if ids || !urls && numPosts != 0 {
fmt.Fprintf(tw, "%s\t%s\t\n", "ID", "Token")
} else if numPosts != 0 {
fmt.Fprintf(tw, "%s\t%s\t\n", "URL", "Token")
} else { } else {
fmt.Fprintf(tw, "unsynced\t%s\t%s\t\n", getPostURL(c, p.ID), p.EditToken)
fmt.Fprintf(tw, "No local posts found\n")
} }
}
u, _ := config.LoadUser(config.UserDataDir(c.App.ExtraInfo()["configDir"]))
if u != nil {
remotePosts, err := api.GetUserPosts(c)
if err != nil {
fmt.Println(err)
}

if len(remotePosts) > 0 {
identifier := "URL"
for i := range *posts {
p = (*posts)[numPosts-1-i]
if ids || !urls { if ids || !urls {
identifier = "ID"
fmt.Fprintf(tw, "%s\t%s\t\n", p.ID, p.EditToken)
} else {
fmt.Fprintf(tw, "%s\t%s\t\n", getPostURL(c, p.ID), p.EditToken)
} }
fmt.Fprintf(tw, "\nAccount\t%s\t%s\t\n", identifier, "Title")
} }
for _, p := range remotePosts {
identifier := getPostURL(c, p.ID)
if ids || !urls {
identifier = p.ID
}
synced := "unsynced"
if p.Synced {
synced = "synced"
}
fmt.Fprintf(tw, "%s\t%s\t%s\t\n", synced, identifier, p.Title)
return tw.Flush()
}

for _, p := range *posts {
if ids || !urls {
fmt.Printf("%s\n", p.ID)
} else {
fmt.Printf("%s\n", getPostURL(c, p.ID))
} }
} }
return tw.Flush()
return nil
} }


func getPostURL(c *cli.Context, slug string) string { func getPostURL(c *cli.Context, slug string) string {


Laddar…
Avbryt
Spara