refactor: cleanup some functions
This commit is contained in:
parent
2ba19954d6
commit
cb4e946ba2
11
cmd/utils.go
11
cmd/utils.go
@ -148,16 +148,16 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := &pythonData{hadDB: true}
|
data := &pythonData{hadDB: true}
|
||||||
|
|
||||||
path := v.GetString("database")
|
path := v.GetString("database")
|
||||||
|
|
||||||
absPath, err := filepath.Abs(path)
|
absPath, err := filepath.Abs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
exists, err := dbExists(path)
|
|
||||||
|
|
||||||
|
exists, err := dbExists(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
} else if exists && cfg.noDB {
|
} else if exists && cfg.noDB {
|
||||||
log.Fatal(absPath + " already exists")
|
log.Fatal(absPath + " already exists")
|
||||||
} else if !exists && !cfg.noDB && !cfg.allowNoDB {
|
} else if !exists && !cfg.noDB && !cfg.allowNoDB {
|
||||||
@ -168,15 +168,18 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
|
|||||||
|
|
||||||
log.Println("Using database: " + absPath)
|
log.Println("Using database: " + absPath)
|
||||||
data.hadDB = exists
|
data.hadDB = exists
|
||||||
|
|
||||||
db, err := storm.Open(path, storm.BoltOptions(databasePermissions, nil))
|
db, err := storm.Open(path, storm.BoltOptions(databasePermissions, nil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
data.store, err = bolt.NewStorage(db)
|
data.store, err = bolt.NewStorage(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return fn(cmd, args, v, data)
|
return fn(cmd, args, v, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user