diff --git a/jobs/sync-anime/shell.go b/jobs/sync-anime/shell.go new file mode 100644 index 00000000..96a3802d --- /dev/null +++ b/jobs/sync-anime/shell.go @@ -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 +} diff --git a/jobs/sync-anime/sync-anime.go b/jobs/sync-anime/sync-anime.go index 2936758b..65002a1b 100644 --- a/jobs/sync-anime/sync-anime.go +++ b/jobs/sync-anime/sync-anime.go @@ -13,6 +13,12 @@ import ( func main() { color.Yellow("Syncing Anime") + // In case we refresh only one anime + if InvokeShellArgs() { + color.Green("Finished.") + return + } + // Get a stream of all anime allAnime := kitsu.StreamAnimeWithMappings() @@ -24,7 +30,7 @@ func main() { color.Green("Finished.") } -func sync(data *kitsu.Anime) { +func sync(data *kitsu.Anime) *arn.Anime { anime, err := arn.GetAnime(data.ID) if err != nil { @@ -136,4 +142,6 @@ func sync(data *kitsu.Anime) { // Log fmt.Println(status, anime.ID, anime.Title.Canonical) + + return anime }