go-mastodon/cmd/mstdn/cmd_toot.go

34 lines
610 B
Go
Raw Normal View History

2017-04-15 14:52:11 +02:00
package main
import (
"context"
2017-04-15 14:52:11 +02:00
"errors"
"fmt"
2017-04-15 14:52:11 +02:00
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
)
func cmdToot(c *cli.Context) error {
var toot string
ff := c.String("ff")
if ff != "" {
text, err := readFile(ff)
if err != nil {
2017-04-24 12:40:20 +02:00
return err
2017-04-15 14:52:11 +02:00
}
toot = string(text)
} else {
if !c.Args().Present() {
return errors.New("arguments required")
}
2017-04-15 16:21:45 +02:00
toot = argstr(c)
2017-04-15 14:52:11 +02:00
}
client := c.App.Metadata["client"].(*mastodon.Client)
_, err := client.PostStatus(context.Background(), &mastodon.Toot{
2017-04-19 08:17:26 +02:00
Status: toot,
InReplyToID: mastodon.ID(fmt.Sprint(c.Int64("i"))),
2017-04-15 14:52:11 +02:00
})
return err
}