mirror of
https://github.com/1f349/orchid.git
synced 2025-02-05 05:56:40 +00:00
Some further clean up of main and setup
This commit is contained in:
parent
bb7c4bcedc
commit
4105d14e63
@ -27,12 +27,14 @@ func main() {
|
||||
logger.Logger.Info("Starting...")
|
||||
|
||||
if configPath == "" {
|
||||
logger.Logger.Fatal("Config flag is missing")
|
||||
logger.Logger.Error("Config flag is missing")
|
||||
trySetup(configPath)
|
||||
return
|
||||
}
|
||||
|
||||
wd, err := getWD(configPath)
|
||||
if err != nil {
|
||||
logger.Logger.Fatal("Failed to find config directory: ", "err", err)
|
||||
logger.Logger.Fatal("Failed to find config directory", "err", err)
|
||||
}
|
||||
|
||||
// try to open the config file
|
||||
@ -41,19 +43,11 @@ func main() {
|
||||
case err == nil:
|
||||
break
|
||||
case os.IsNotExist(err):
|
||||
// handle potential errors during setup
|
||||
err = trySetup(wd)
|
||||
switch {
|
||||
case errors.Is(err, errExitSetup):
|
||||
// exit setup without questions
|
||||
return
|
||||
case err == nil:
|
||||
logger.Logger.Warn("Failed to open config file", "err", err)
|
||||
trySetup(wd)
|
||||
return
|
||||
default:
|
||||
logger.Logger.Fatal("Failed to run setup", "err", err)
|
||||
}
|
||||
default:
|
||||
logger.Logger.Fatal("Open config file: ", "err", err)
|
||||
logger.Logger.Fatal("Open config file", "err", err)
|
||||
}
|
||||
|
||||
// config file opened with no errors
|
||||
@ -63,7 +57,7 @@ func main() {
|
||||
var config startUpConfig
|
||||
err = yaml.NewDecoder(openConf).Decode(&config)
|
||||
if err != nil {
|
||||
logger.Logger.Fatal("Invalid config file: ", "err", err)
|
||||
logger.Logger.Fatal("Invalid config file", "err", err)
|
||||
}
|
||||
|
||||
runDaemon(wd, config)
|
||||
@ -115,3 +109,17 @@ func getWD(configPath string) (string, error) {
|
||||
}
|
||||
return filepath.Dir(wdAbs), nil
|
||||
}
|
||||
|
||||
func trySetup(wd string) {
|
||||
// handle potential errors during setup
|
||||
err := runSetup(wd)
|
||||
switch {
|
||||
case errors.Is(err, errExitSetup):
|
||||
// exit setup without questions
|
||||
return
|
||||
case err == nil:
|
||||
return
|
||||
default:
|
||||
logger.Logger.Fatal("Failed to run setup", "err", err)
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
|
||||
var errExitSetup = errors.New("exit setup")
|
||||
|
||||
func trySetup(wd string) error {
|
||||
func runSetup(wd string) error {
|
||||
// ask about running the setup steps
|
||||
createFile := false
|
||||
err := survey.AskOne(&survey.Confirm{Message: fmt.Sprintf("Create Orchid config files in this directory: '%s'?", wd)}, &createFile)
|
||||
|
@ -3,12 +3,15 @@ package database
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var errMissingSqlDB = errors.New("cannot open transaction without sql.DB")
|
||||
|
||||
func (q *Queries) UseTx(ctx context.Context, cb func(tx *Queries) error) error {
|
||||
sqlDB, ok := q.db.(*sql.DB)
|
||||
if !ok {
|
||||
panic("cannot open transaction without sql.DB")
|
||||
return errMissingSqlDB
|
||||
}
|
||||
tx, err := sqlDB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user