go-mastodon/cmd/mstdn/cmd_upload.go
Yasuhiro Matsumoto b74e25cee2 add upload command
2017-04-17 13:56:06 +09:00

34 lines
890 B
Go

package main
import (
"context"
"errors"
"fmt"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
)
func cmdUpload(c *cli.Context) error {
if !c.Args().Present() {
return errors.New("arguments required")
}
client := c.App.Metadata["client"].(*mastodon.Client)
for i := 0; i < c.NArg(); i++ {
attachment, err := client.UploadMedia(context.Background(), c.Args().Get(i))
if err != nil {
return err
}
if i > 0 {
fmt.Fprintln(c.App.Writer)
}
fmt.Fprintf(c.App.Writer, "ID : %v\n", attachment.ID)
fmt.Fprintf(c.App.Writer, "Type : %v\n", attachment.Type)
fmt.Fprintf(c.App.Writer, "URL : %v\n", attachment.URL)
fmt.Fprintf(c.App.Writer, "RemoteURL : %v\n", attachment.RemoteURL)
fmt.Fprintf(c.App.Writer, "PreviewURL: %v\n", attachment.PreviewURL)
fmt.Fprintf(c.App.Writer, "TextURL : %v\n", attachment.TextURL)
}
return nil
}