From 04baed6e1a4e9aa35b16c4a08250adc2d5dbdf9b Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 16 Apr 2017 22:26:05 +0900 Subject: [PATCH] small refactoring for tests --- cmd/mstdn/main.go | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/cmd/mstdn/main.go b/cmd/mstdn/main.go index f920d82..a8a6349 100644 --- a/cmd/mstdn/main.go +++ b/cmd/mstdn/main.go @@ -159,21 +159,8 @@ func fatalIf(err error) { os.Exit(1) } -func run() int { - file, config, err := getConfig() - fatalIf(err) - - client := mastodon.NewClient(config) - if config.AccessToken == "" { - err = authenticate(client, config, file) - fatalIf(err) - } - +func makeApp() *cli.App { app := cli.NewApp() - app.Metadata = map[string]interface{}{ - "client": client, - "config": config, - } app.Name = "mstdn" app.Usage = "mastodon client" app.Version = "0.0.1" @@ -220,7 +207,31 @@ func run() int { Usage: "search content", Action: cmdSearch, }, + { + Name: "followers", + Usage: "show followers", + Action: cmdFollowers, + }, } + return app +} + +func run() int { + app := makeApp() + + file, config, err := getConfig() + fatalIf(err) + + client := mastodon.NewClient(config) + if config.AccessToken == "" { + err = authenticate(client, config, file) + fatalIf(err) + } + app.Metadata = map[string]interface{}{ + "client": client, + "config": config, + } + app.Run(os.Args) return 0 }