Browse Source

Keep new post listing style under -v flag

pull/40/head
Matt Baer 4 years ago
parent
commit
73501ae46e
2 changed files with 26 additions and 4 deletions
  1. +2
    -1
      GUIDE.md
  2. +24
    -3
      commands/commands.go

+ 2
- 1
GUIDE.md View File

@@ -100,7 +100,8 @@ $ writeas posts -url
https://write.as/aaaazzzzzzzza

$ writeas posts -v
aaaazzzzzzzza | dhuieoj23894jhf984hdfs9834hdf84j
ID Token
aaaazzzzzzzza dhuieoj23894jhf984hdfs9834hdf84j
```

#### Delete a post


+ 24
- 3
commands/commands.go View File

@@ -169,10 +169,31 @@ func CmdListPosts(c *cli.Context) error {
details := c.Bool("v")

posts := api.GetPosts(c)

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, "No local posts found\n")
}
for i := range *posts {
p = (*posts)[numPosts-1-i]
if ids || !urls {
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)
}
}
return tw.Flush()
}

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


Loading…
Cancel
Save