From 3a545132283c89b4197a13726d79bbb81df34312 Mon Sep 17 00:00:00 2001 From: HAYAMA_Kaoru Date: Fri, 14 Apr 2017 11:32:02 +0900 Subject: [PATCH] New option: -ff FILENAME: post utf8 string from a file("-" means STDIN) --- cmd/mstdn/main.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/mstdn/main.go b/cmd/mstdn/main.go index 423269d..c0ed9a0 100644 --- a/cmd/mstdn/main.go +++ b/cmd/mstdn/main.go @@ -22,10 +22,19 @@ import ( ) var ( - toot = flag.String("t", "", "toot text") - stream = flag.Bool("S", false, "streaming public") + 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{