Also: - Fixed the Makefile - Added a Taskfile.yml (see: https://taskfile.dev) - Updated the manual page Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
49 lines
883 B
Go
49 lines
883 B
Go
package main
|
|
|
|
import (
|
|
"git.laidback.moe/shinyoukai/mikuru"
|
|
"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(mikuru.Config.Host),
|
|
client.WithToken(mikuru.Config.Token),
|
|
)
|
|
if err != nil {
|
|
log.Fatal("Unable to create client", err)
|
|
}
|
|
write(cli)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(postCmd)
|
|
mikuru.ConfInit()
|
|
}
|
|
|
|
func write(cli *client.Client) {
|
|
var post string
|
|
|
|
data, err := editor.Read()
|
|
|
|
if err != nil {
|
|
log.Fatal("Unable to read content from editor", err)
|
|
}
|
|
|
|
post = string(data)
|
|
|
|
_, err = cli.Post(post, "")
|
|
|
|
if err != nil {
|
|
log.Fatal("Unable to publish tweet", err)
|
|
}
|
|
}
|