-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (56 loc) · 1.52 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
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"thwInventoryMerge/app"
"thwInventoryMerge/config"
"thwInventoryMerge/utils"
)
func main() {
logger := utils.NewLogger()
var configPath string
var step string
flag.StringVar(&configPath, "c", "config.json", "the config file path")
flag.StringVar(&step, "s", "process", "the inventory step")
flag.Parse()
executablePath := getExecutablePath(logger)
if configPath == "" {
configPath = filepath.Join(executablePath, "config.json")
}
config, err := config.LoadConfig(configPath, logger)
if err != nil {
log.Fatalf("Failed to load config from path %s: %v", configPath, err)
}
if config.WorkingDir == "" {
config.WorkingDir = executablePath
}
switch step {
case "init":
fmt.Println("Running initialization step")
err := app.NewInitInventoryCSVStep(*config, logger).Init()
if err != nil {
logger.Fatal(fmt.Sprintf("Failed to init inventory csv: %v", err))
}
case "process":
fmt.Println("Running inventory step")
err := app.NewProcessInvetoryStep(*config, logger).Process()
if err != nil {
logger.Fatal(fmt.Sprintf("Failed to process inventory: %v", err))
}
default:
logger.Fatal(fmt.Sprintf("Invalid step: %s", step))
}
// Keep the terminal open
fmt.Println("Press Enter to exit...")
fmt.Scanln()
}
func getExecutablePath(logger utils.Logger) string {
exePath, err := os.Executable()
if err != nil {
logger.Fatal(fmt.Sprintf("Failed to get executable path: %v", err))
}
return filepath.Dir(exePath)
}