-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (50 loc) · 1.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"os"
"github.com/alecthomas/kong"
"github.com/rs/zerolog/log"
"github.com/eriq-augustine/comic-server/config"
"github.com/eriq-augustine/comic-server/database"
"github.com/eriq-augustine/comic-server/metadata"
)
var args struct {
config.ConfigArgs
Path []string `help:"Target paths to import." arg:"" type:"path"`
}
func main() {
kong.Parse(&args);
err := config.HandleConfigArgs(args.ConfigArgs);
if (err != nil) {
log.Fatal().Err(err).Msg("Could not load config options.");
}
err = database.Open();
if (err != nil) {
log.Fatal().Err(err).Msg("Could not open database.");
}
defer database.Close();
numNewArchives := 0;
numExistingArchives := 0;
numErrorArchives := 0;
for _, target := range args.Path {
newArchives, err := metadata.ImportPath(target);
if (err != nil) {
log.Error().Err(err).Str("path", target).Msg("Failed to import all archives on path.");
continue;
}
for _, archive := range newArchives {
if (archive == nil) {
numErrorArchives++;
} else if (archive.New) {
numNewArchives++;
} else {
numExistingArchives++;
}
}
}
fmt.Printf("Encountered %d new, %d existing, and %d erroneous archives.\n", numNewArchives, numExistingArchives, numErrorArchives);
if (numErrorArchives > 0) {
os.Exit(1);
}
os.Exit(0);
}