add follow command

This commit is contained in:
Yasuhiro Matsumoto 2017-04-19 14:17:18 +09:00
parent fe02b9e6af
commit 5a6f6f16f1
2 changed files with 35 additions and 0 deletions

30
cmd/mstdn/cmd_follow.go Normal file
View File

@ -0,0 +1,30 @@
package main
import (
"context"
"errors"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
)
func cmdFollow(c *cli.Context) error {
client := c.App.Metadata["client"].(*mastodon.Client)
if !c.Args().Present() {
return errors.New("arguments required")
}
for i := 0; i < c.NArg(); i++ {
account, err := client.AccountsSearch(context.Background(), c.Args().Get(i), 1)
if err != nil {
return err
}
if len(account) == 0 {
continue
}
_, err = client.AccountFollow(context.Background(), account[0].ID)
if err != nil {
return err
}
}
return nil
}

View File

@ -222,6 +222,11 @@ func makeApp() *cli.App {
Usage: "show followers", Usage: "show followers",
Action: cmdFollowers, Action: cmdFollowers,
}, },
{
Name: "follow",
Usage: "follow account",
Action: cmdFollow,
},
{ {
Name: "upload", Name: "upload",
Usage: "upload file", Usage: "upload file",