49 lines
907 B
Go
49 lines
907 B
Go
package main
|
|
|
|
import (
|
|
"git.laidback.moe/shinyoukai/mikuru/mirai"
|
|
"go.yarn.social/client"
|
|
"github.com/tj/go-editor"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var postCmd = &cobra.Command{
|
|
Use: "post",
|
|
Aliases: []string{"tweet"},
|
|
Short: "Publish a new post to a Yarn pod",
|
|
Run: func(_ *cobra.Command, args []string) {
|
|
cli, err := client.NewClient(
|
|
client.WithURI(mirai.Config.Host),
|
|
client.WithToken(mirai.Config.Token),
|
|
)
|
|
if err != nil {
|
|
log.Fatalf("Unable to create client\n%s\n", err)
|
|
}
|
|
write(cli)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(postCmd)
|
|
mirai.ConfInit()
|
|
}
|
|
|
|
func write(cli *client.Client) {
|
|
var post string
|
|
|
|
data, err := editor.Read()
|
|
|
|
if err != nil {
|
|
log.Fatalf("Unable to read content from editor\n%s\n", err)
|
|
}
|
|
|
|
post = string(data)
|
|
|
|
_, err = cli.Post(post, "")
|
|
|
|
if err != nil {
|
|
log.Fatalf("Unable to publish tweet\n%s\n", err)
|
|
}
|
|
}
|