From 5a6f6f16f1fca71be646dccb097bd42966bfbe5b Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 19 Apr 2017 14:17:18 +0900 Subject: [PATCH] add follow command --- cmd/mstdn/cmd_follow.go | 30 ++++++++++++++++++++++++++++++ cmd/mstdn/main.go | 5 +++++ 2 files changed, 35 insertions(+) create mode 100644 cmd/mstdn/cmd_follow.go diff --git a/cmd/mstdn/cmd_follow.go b/cmd/mstdn/cmd_follow.go new file mode 100644 index 0000000..e064f03 --- /dev/null +++ b/cmd/mstdn/cmd_follow.go @@ -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 +} diff --git a/cmd/mstdn/main.go b/cmd/mstdn/main.go index e24586a..7030370 100644 --- a/cmd/mstdn/main.go +++ b/cmd/mstdn/main.go @@ -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",