Skip to content

Commit 72444b0

Browse files
committed
Add --md flag
This returns URLs with Markdown enabled. Part of #14
1 parent 70c9e28 commit 72444b0

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

GUIDE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ Hello world!
6161

6262
#### List all published posts
6363

64-
This lists all posts you've published from your device. Pass the `--url` flag to show the list with full URLs.
64+
This lists all posts you've published from your device.
65+
66+
Pass the `--url` flag to show the list with full post URLs, and the `--md` flag to return URLs with Markdown enabled.
6567

6668
```bash
6769
$ writeas list
@@ -101,3 +103,5 @@ Customize your post's appearance with the `--font` flag:
101103
| `code` | Syntax-highlighted monospace | No |
102104

103105
Put it all together, e.g. publish with a sans-serif font: `writeas new --font sans`
106+
107+
If you're publishing Markdown, supply the `--md` flag to get a URL back that will render Markdown, e.g.: `writeas new --font sans --md`

cmd/writeas/api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func DoPost(c *cli.Context, post []byte, font string, encrypt, tor, code bool) e
112112

113113
addPost(id, token)
114114

115+
// Output URL in requested format
116+
if c.Bool("md") {
117+
url = append(url, []byte(".md")...)
118+
}
115119
// Copy URL to clipboard
116120
err = clipboard.WriteAll(string(url))
117121
if err != nil {

cmd/writeas/cli.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ var postFlags = []cli.Flag{
4040
Name: "code",
4141
Usage: "Specifies this post is code",
4242
},
43+
cli.BoolFlag{
44+
Name: "md",
45+
Usage: "Returns post URL with Markdown enabled",
46+
},
4347
cli.BoolFlag{
4448
Name: "verbose, v",
4549
Usage: "Make the operation more talkative",
@@ -186,6 +190,10 @@ func main() {
186190
Name: "id",
187191
Usage: "Show list with post IDs (default)",
188192
},
193+
cli.BoolFlag{
194+
Name: "md",
195+
Usage: "Use with --url to return URLs with Markdown enabled",
196+
},
189197
cli.BoolFlag{
190198
Name: "url",
191199
Usage: "Show list with URLs",

cmd/writeas/commands.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ func cmdList(c *cli.Context) error {
146146
fmt.Printf("%s ", p.ID)
147147
}
148148
if urls {
149-
fmt.Printf("https://write.as/%s ", p.ID)
149+
ext := ""
150+
// Output URL in requested format
151+
if c.Bool("md") {
152+
ext = ".md"
153+
}
154+
fmt.Printf("https://write.as/%s%s ", p.ID, ext)
150155
}
151156
fmt.Print("\n")
152157
}

0 commit comments

Comments
 (0)