New option: -ff FILENAME: post utf8 string from a file("-" means STDIN)

pull/3/head
HAYAMA_Kaoru 2017-04-14 11:32:02 +09:00
parent ae1467926c
commit 3a54513228
1 changed files with 24 additions and 2 deletions

View File

@ -24,8 +24,17 @@ import (
var (
toot = flag.String("t", "", "toot text")
stream = flag.Bool("S", false, "streaming public")
fromfile = flag.String("ff", "", "post utf-8 string from a file(\"-\" means STDIN)")
)
func readFile(filename string) ([]byte, error) {
if filename == "-" {
return ioutil.ReadAll(os.Stdin)
} else {
return ioutil.ReadFile(filename)
}
}
func extractText(node *html.Node, w *bytes.Buffer) {
if node.Type == html.TextNode {
data := strings.Trim(node.Data, "\r\n")
@ -136,6 +145,19 @@ func main() {
}
return
}
if *fromfile != "" {
text, err := readFile(*fromfile)
if err != nil {
log.Fatal(err)
}
_, err = client.PostStatus(&mastodon.Toot{
Status: string(text),
})
if err != nil {
log.Fatal(err)
}
return
}
if *toot != "" {
_, err = client.PostStatus(&mastodon.Toot{