Added shell flags

This commit is contained in:
Eduard Urbach 2017-11-09 14:36:47 +01:00
parent 20a92bef77
commit 1ee4619310

View File

@ -1,10 +1,12 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"path" "path"
"runtime" "runtime"
"sort"
"strings" "strings"
"time" "time"
@ -19,7 +21,18 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
) )
var ticker = time.NewTicker(100 * time.Millisecond) var ticker = time.NewTicker(200 * time.Millisecond)
// Shell parameters
var from int
var to int
// Shell flags
func init() {
flag.IntVar(&from, "from", 0, "From index")
flag.IntVar(&to, "to", 0, "To index")
flag.Parse()
}
func main() { func main() {
color.Yellow("Downloading anime images") color.Yellow("Downloading anime images")
@ -27,6 +40,20 @@ func main() {
allAnime := arn.AllAnime() allAnime := arn.AllAnime()
sort.Slice(allAnime, func(i, j int) bool {
return allAnime[i].Title.Canonical < allAnime[j].Title.Canonical
})
if from < 0 {
from = 0
}
if to > len(allAnime) {
to = len(allAnime)
}
allAnime = allAnime[from:to]
for index, anime := range allAnime { for index, anime := range allAnime {
fmt.Printf("%d / %d\n", index+1, len(allAnime)) fmt.Printf("%d / %d\n", index+1, len(allAnime))
work(anime) work(anime)