small refactoring for tests

pull/19/head
Yasuhiro Matsumoto 2017-04-16 22:26:05 +09:00
parent 70798b2839
commit 04baed6e1a
1 changed files with 25 additions and 14 deletions

View File

@ -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
}