-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
75 lines (69 loc) · 2.43 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
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"nft/functional/combiner"
"nft/functional/domain"
"nft/functional/generator"
"nft/functional/helpers"
"nft/functional/inmemory"
"nft/functional/pinata"
"nft/functional/trait"
"os"
)
func main() {
// Flags.
appContext := domain.NewAppContext()
// Generator flags.
flag.IntVar(&appContext.GeneratorParams.Length, "generated-image-length", 2048, "generated image length")
flag.IntVar(&appContext.GeneratorParams.Width, "generated-image-width", 2048, "generated image width")
flag.StringVar(&appContext.GeneratorParams.InputDirectory, "generated-image-input", "input-dir", "generated image input directory")
flag.StringVar(&appContext.GeneratorParams.OutputDirectory, "generated-image-output", "output-dir", "generated image output directory")
flag.IntVar(&appContext.GeneratorParams.Number, "generated-image-number", 100, "generated image number")
generate := flag.Bool("generate", false, "Generate images")
// Ipfs flags.
flag.StringVar(&appContext.IpfsParams.InputDirectory, "ipfs-input", "output-dir", "ipfs input directory")
flag.StringVar(&appContext.IpfsParams.OutputDirectory, "ipfs-output", "ipfs-metadata", "ipfs input directory")
flag.StringVar(&appContext.IpfsParams.APIKey, "ipfs-api-key", "", "ipfs api key")
flag.StringVar(&appContext.IpfsParams.SecretKey, "ipfs-secret-key", "", "ipfs secret key")
ipfsUpload := flag.Bool("ipfs-upload", false, "Upload files to ipfs")
// Other.
printInfo := flag.Bool("info", false, "Print info")
flag.CommandLine.SetOutput(os.Stdout)
flag.Parse()
if *generate {
fmt.Println("Start generating images ...")
traitService := trait.NewBasicTraitService(
inmemory.NewGroupRepository(),
inmemory.NewTraitRepository(),
)
_, err := traitService.Import(appContext.GeneratorParams.InputDirectory)
if err != nil {
panic(err)
}
generatorService := generator.NewBasicImageGenerator(
appContext.GeneratorParams,
traitService,
combiner.NewBasicImageCombiner(),
)
err = generatorService.GenerateImages()
if err != nil {
panic(err)
}
return
}
if *ipfsUpload {
fmt.Println("Uploading files to ipfs ...")
ipfsService := pinata.NewIpfsService(appContext.IpfsParams)
if err := ipfsService.UploadImages(); err != nil {
panic(err)
}
}
if *printInfo {
helpers.PrintInfoV2(
appContext.IpfsParams.OutputDirectory,
appContext.GeneratorParams.OutputDirectory,
)
helpers.PrintInfo(appContext.GeneratorParams.OutputDirectory)
}
}