Преглед изворни кода

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

revert posts listing style to v1.2
pull/41/head
Matt Baer пре 4 година
committed by GitHub
родитељ
комит
f1947e48e2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 измењених фајлова са 41 додато и 45 уклоњено
  1. +11
    -6
      GUIDE.md
  2. +5
    -1
      cmd/writeas/main.go
  3. +25
    -38
      commands/commands.go

+ 11
- 6
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


+ 5
- 1
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 <username>.",
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",


+ 25
- 38
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 {


Loading…
Откажи
Сачувај