mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix(autobrrctl): missing logger (#355)
This commit is contained in:
parent
01888aeb1c
commit
8a4826d781
2 changed files with 20 additions and 3 deletions
|
@ -8,8 +8,10 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/autobrr/autobrr/internal/config"
|
||||||
"github.com/autobrr/autobrr/internal/database"
|
"github.com/autobrr/autobrr/internal/database"
|
||||||
"github.com/autobrr/autobrr/internal/domain"
|
"github.com/autobrr/autobrr/internal/domain"
|
||||||
|
"github.com/autobrr/autobrr/internal/logger"
|
||||||
"github.com/autobrr/autobrr/pkg/argon2id"
|
"github.com/autobrr/autobrr/pkg/argon2id"
|
||||||
"github.com/autobrr/autobrr/pkg/errors"
|
"github.com/autobrr/autobrr/pkg/errors"
|
||||||
|
|
||||||
|
@ -21,6 +23,7 @@ const usage = `usage: autobrrctl --config path <action>
|
||||||
|
|
||||||
create-user <username> Create user
|
create-user <username> Create user
|
||||||
change-password <username> Change password for user
|
change-password <username> Change password for user
|
||||||
|
version Print version info
|
||||||
help Show this help message
|
help Show this help message
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -30,6 +33,12 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
version = "dev"
|
||||||
|
commit = ""
|
||||||
|
date = ""
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var configPath string
|
var configPath string
|
||||||
flag.StringVar(&configPath, "config", "", "path to configuration file")
|
flag.StringVar(&configPath, "config", "", "path to configuration file")
|
||||||
|
@ -39,15 +48,23 @@ func main() {
|
||||||
log.Fatal("--config required")
|
log.Fatal("--config required")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read config
|
||||||
|
cfg := config.New(configPath, version)
|
||||||
|
|
||||||
|
// init new logger
|
||||||
|
l := logger.New(cfg.Config)
|
||||||
|
|
||||||
// open database connection
|
// open database connection
|
||||||
db, _ := database.NewDB(&domain.Config{ConfigPath: configPath, DatabaseType: "sqlite"}, nil)
|
db, _ := database.NewDB(cfg.Config, l)
|
||||||
if err := db.Open(); err != nil {
|
if err := db.Open(); err != nil {
|
||||||
log.Fatal("could not open db connection")
|
log.Fatal("could not open db connection")
|
||||||
}
|
}
|
||||||
|
|
||||||
userRepo := database.NewUserRepo(nil, db)
|
userRepo := database.NewUserRepo(l, db)
|
||||||
|
|
||||||
switch cmd := flag.Arg(0); cmd {
|
switch cmd := flag.Arg(0); cmd {
|
||||||
|
case "version":
|
||||||
|
fmt.Fprintf(flag.CommandLine.Output(), "Version: %v\nCommit: %v\nBuild: %v\n", version, commit, date)
|
||||||
case "create-user":
|
case "create-user":
|
||||||
username := flag.Arg(1)
|
username := flag.Arg(1)
|
||||||
if username == "" {
|
if username == "" {
|
||||||
|
|
|
@ -46,7 +46,7 @@ func NewDB(cfg *domain.Config, log logger.Logger) (*DB, error) {
|
||||||
db.DSN = fmt.Sprintf("postgres://%v:%v@%v:%d/%v?sslmode=disable", cfg.PostgresUser, cfg.PostgresPass, cfg.PostgresHost, cfg.PostgresPort, cfg.PostgresDatabase)
|
db.DSN = fmt.Sprintf("postgres://%v:%v@%v:%d/%v?sslmode=disable", cfg.PostgresUser, cfg.PostgresPass, cfg.PostgresHost, cfg.PostgresPort, cfg.PostgresDatabase)
|
||||||
db.Driver = "postgres"
|
db.Driver = "postgres"
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unsupported databse: %v", cfg.DatabaseType)
|
return nil, errors.New("unsupported database: %v", cfg.DatabaseType)
|
||||||
}
|
}
|
||||||
|
|
||||||
return db, nil
|
return db, nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue