add follow command

pull/28/head
Yasuhiro Matsumoto 2017-04-19 14:17:18 +09:00
parent fe02b9e6af
commit 5a6f6f16f1
2 changed files with 35 additions and 0 deletions

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",
Action: cmdFollowers,
},
{
Name: "follow",
Usage: "follow account",
Action: cmdFollow,
},
{
Name: "upload",
Usage: "upload file",