Skip to content

Commit 21c1f28

Browse files
committed
add markdown output
1 parent e0f10ec commit 21c1f28

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ Create a new poll for who is the best ferret.
2828
$ polls new Tobi Loki Jane
2929
```
3030

31+
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z07AGE7KBMK8T2RFJCBWY/Tobi)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z07AGE7KBMK8T2RFJCBWY/Tobi/vote)
32+
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z07AGE7KBMK8T2RFJCBWY/Loki)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z07AGE7KBMK8T2RFJCBWY/Loki/vote)
33+
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z07AGE7KBMK8T2RFJCBWY/Jane)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z07AGE7KBMK8T2RFJCBWY/Jane/vote)
34+
3135
Create a new poll with larger options.
3236

3337
```
3438
$ polls new "Cats are better" "Ferrets are better"
3539
```
3640

41+
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z0HTHT9P5TXGREGP1T29F/Cats%20are%20better)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z0HTHT9P5TXGREGP1T29F/Cats%20are%20better/vote)
42+
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z0HTHT9P5TXGREGP1T29F/Ferrets%20are%20better)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/01BM2Z0HTHT9P5TXGREGP1T29F/Ferrets%20are%20better/vote)
43+
3744
---
3845

3946
[![GoDoc](https://godoc.org/github.com/tj/gh-polls?status.svg)](https://godoc.org/github.com/tj/gh-polls)

cmd/polls/main.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log"
88
"net/http"
9+
"net/url"
910
"os"
1011

1112
"github.com/tj/kingpin"
@@ -17,7 +18,7 @@ var version = "0.0.1"
1718
// endpoint for polls.
1819
var endpoint = "https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod"
1920

20-
// TODO: move this stuff to some client lib.
21+
// TODO: move all this stuff into a pkg
2122
type input struct {
2223
Options []string `json:"body"`
2324
}
@@ -37,6 +38,8 @@ func main() {
3738

3839
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
3940
case create.FullCommand():
41+
// TODO: move all this stuff into a pkg
42+
4043
b, err := json.Marshal(input{Options: *options})
4144
if err != nil {
4245
log.Fatalf("error marshaling: %s", err)
@@ -53,6 +56,16 @@ func main() {
5356
log.Fatalf("error unmarshaling resonse: %s", err)
5457
}
5558

56-
fmt.Println(out.ID)
59+
for _, o := range *options {
60+
fmt.Println(link(out.ID, o))
61+
}
5762
}
5863
}
64+
65+
func link(id, option string) string {
66+
return fmt.Sprintf(`[%s](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/%s/%s/vote)`, image(id, option), id, url.PathEscape(option))
67+
}
68+
69+
func image(id, option string) string {
70+
return fmt.Sprintf(`![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/%s/%s)`, id, url.PathEscape(option))
71+
}

0 commit comments

Comments
 (0)