Improved shell commandline for anime sync

This commit is contained in:
Eduard Urbach 2017-07-07 18:28:25 +02:00
parent 17c9499601
commit 343dfcb75b
2 changed files with 59 additions and 1 deletions

50
jobs/sync-anime/shell.go Normal file
View File

@ -0,0 +1,50 @@
package main
import (
"errors"
"flag"
"github.com/animenotifier/arn"
"github.com/animenotifier/kitsu"
"github.com/fatih/color"
)
// Shell parameters
var animeID string
var verbose bool
// Shell flags
func init() {
flag.StringVar(&animeID, "id", "", "ID of the anime that you want to refresh")
flag.BoolVar(&verbose, "v", false, "Verbose output")
flag.Parse()
}
// InvokeShellArgs ...
func InvokeShellArgs() bool {
if animeID != "" {
kitsuAnime, err := kitsu.GetAnime(animeID)
if err != nil {
panic(err)
}
if kitsuAnime.ID != animeID {
panic(errors.New("Anime ID is not the same"))
}
anime := sync(kitsuAnime)
if verbose {
color.Cyan("Kitsu:")
arn.PrettyPrint(kitsuAnime)
color.Cyan("ARN:")
arn.PrettyPrint(anime)
}
return true
}
return false
}

View File

@ -13,6 +13,12 @@ import (
func main() { func main() {
color.Yellow("Syncing Anime") color.Yellow("Syncing Anime")
// In case we refresh only one anime
if InvokeShellArgs() {
color.Green("Finished.")
return
}
// Get a stream of all anime // Get a stream of all anime
allAnime := kitsu.StreamAnimeWithMappings() allAnime := kitsu.StreamAnimeWithMappings()
@ -24,7 +30,7 @@ func main() {
color.Green("Finished.") color.Green("Finished.")
} }
func sync(data *kitsu.Anime) { func sync(data *kitsu.Anime) *arn.Anime {
anime, err := arn.GetAnime(data.ID) anime, err := arn.GetAnime(data.ID)
if err != nil { if err != nil {
@ -136,4 +142,6 @@ func sync(data *kitsu.Anime) {
// Log // Log
fmt.Println(status, anime.ID, anime.Title.Canonical) fmt.Println(status, anime.ID, anime.Title.Canonical)
return anime
} }