add upload command

This commit is contained in:
Yasuhiro Matsumoto 2017-04-17 13:56:06 +09:00
parent af67397430
commit b74e25cee2
2 changed files with 38 additions and 0 deletions

33
cmd/mstdn/cmd_upload.go Normal file
View File

@ -0,0 +1,33 @@
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
}

View File

@ -213,6 +213,11 @@ func makeApp() *cli.App {
Usage: "show followers",
Action: cmdFollowers,
},
{
Name: "upload",
Usage: "upload file",
Action: cmdUpload,
},
}
return app
}