Skip to content

Commit 2ad7bab

Browse files
committed
add copying to clipboard
1 parent 1803ab9 commit 2ad7bab

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/polls/main.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
"io"
78
"log"
89
"net/http"
910
"net/url"
1011
"os"
1112

13+
"github.com/atotto/clipboard"
14+
1215
"github.com/tj/kingpin"
1316
)
1417

@@ -56,9 +59,17 @@ func main() {
5659
log.Fatalf("error unmarshaling resonse: %s", err)
5760
}
5861

62+
var buf bytes.Buffer
63+
5964
for _, o := range *options {
60-
fmt.Println(link(out.ID, o))
65+
fmt.Fprintf(&buf, link(out.ID, o))
6166
}
67+
68+
if err := clipboard.WriteAll(buf.String()); err == nil {
69+
fmt.Fprintln(os.Stderr, "Copied to clipboard!")
70+
}
71+
72+
io.Copy(os.Stdout, &buf)
6273
}
6374
}
6475

0 commit comments

Comments
 (0)