Adapts database initialization
This commit is contained in:
parent
ccc85259cb
commit
4436b83a15
1 changed files with 3 additions and 9 deletions
12
cmd/root.go
12
cmd/root.go
|
|
@ -17,7 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"freed/internal/database"
|
"freed/internal/database"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -37,7 +36,6 @@ type Config struct {
|
||||||
|
|
||||||
type AppContext struct {
|
type AppContext struct {
|
||||||
Config Config
|
Config Config
|
||||||
DB *sql.DB
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -67,7 +65,6 @@ func Execute() {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(initConfig, initDB)
|
cobra.OnInitialize(initConfig, initDB)
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default: ~/.config/freed/config.toml)")
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default: ~/.config/freed/config.toml)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,11 +101,8 @@ func initConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDB() {
|
func initDB() {
|
||||||
db, err := database.Connect(appContext.Config.DB.Path)
|
if err := database.Open(appContext.Config.DB.Path); err != nil {
|
||||||
|
fmt.Printf("Could not connect to database: %s", err)
|
||||||
if err != nil {
|
os.Exit(1)
|
||||||
fmt.Printf("Could not connect to the database: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
appContext.DB = db
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue