diff --git a/GUIDE.md b/GUIDE.md index 864ae45..5ed6e63 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -84,19 +84,24 @@ user An Example Blog 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. +To see post IDs with their Edit Tokens pass the `--v` flag. + ```bash $ 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 diff --git a/cmd/writeas/main.go b/cmd/writeas/main.go index c113d19..06d8af5 100644 --- a/cmd/writeas/main.go +++ b/cmd/writeas/main.go @@ -153,7 +153,7 @@ func main() { { Name: "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 .", + Description: "This will list only local posts.", Action: commands.CmdListPosts, Flags: []cli.Flag{ cli.BoolFlag{ @@ -168,6 +168,10 @@ func main() { Name: "url", Usage: "Show list with URLs", }, + cli.BoolFlag{ + Name: "verbose, v", + Usage: "Show verbose post listing, including Edit Tokens", + }, }, }, { Name: "blogs", diff --git a/commands/commands.go b/commands/commands.go index 0a4ba6a..8627411 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -166,53 +166,40 @@ func CmdAdd(c *cli.Context) error { func CmdListPosts(c *cli.Context) error { urls := c.Bool("url") ids := c.Bool("id") + details := c.Bool("v") - var p api.Post 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 { - 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 { - 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 {