go: add importFlag
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2023-07-19 18:25:46 +02:00
parent 4ceb19f4dc
commit 7cf26a73e3
Signed by: wanderer
SSH Key Fingerprint: SHA256:MdCZyJ2sHLltrLBp0xQO0O1qTW9BT/xl5nXkDvhlMCI

17
run.go

@ -64,6 +64,7 @@ var (
configIsPathFlag = flag.Bool("configIsPath", true, "Whether the provided config is path or raw config")
devel = flag.Bool("devel", false, "Run the application in dev mode, connect to a local browser-sync instance for hot-reloading")
license = flag.Bool("license", false, "Print licensing information and exit")
importFlag = flag.String("import", "", "Path to import breach data from")
version = "dev"
// the global logger.
slogger *slogging.Slogger
@ -71,7 +72,7 @@ var (
log slogging.Slogger
)
func run() error {
func run() error { //nolint:gocognit
flag.Parse()
if *license {
@ -79,7 +80,15 @@ func run() error {
return nil
}
printHeader()
var doingImport bool
if importFlag != nil && *importFlag != "" {
doingImport = true
}
if !doingImport {
printHeader()
}
// TODO: allow different configuration formats (toml, ini)
// TODO: rename main.go to pcmt.go
@ -139,6 +148,10 @@ func run() error {
db, err := ent.Open(setting.DbType(), setting.DbConnstring())
if err != nil {
if doingImport {
log.Error("import not possible")
}
return fmt.Errorf("failed to open a connection to database: %v", err)
}
defer db.Close()