From 8a4826d781122b88d2fcba8bc8d52ef8bf41f2d1 Mon Sep 17 00:00:00 2001 From: Ludvig Lundgren Date: Sat, 16 Jul 2022 17:59:24 +0200 Subject: [PATCH] fix(autobrrctl): missing logger (#355) --- cmd/autobrrctl/main.go | 21 +++++++++++++++++++-- internal/database/database.go | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cmd/autobrrctl/main.go b/cmd/autobrrctl/main.go index d2c57d2..4002b18 100644 --- a/cmd/autobrrctl/main.go +++ b/cmd/autobrrctl/main.go @@ -8,8 +8,10 @@ import ( "log" "os" + "github.com/autobrr/autobrr/internal/config" "github.com/autobrr/autobrr/internal/database" "github.com/autobrr/autobrr/internal/domain" + "github.com/autobrr/autobrr/internal/logger" "github.com/autobrr/autobrr/pkg/argon2id" "github.com/autobrr/autobrr/pkg/errors" @@ -21,6 +23,7 @@ const usage = `usage: autobrrctl --config path create-user Create user change-password Change password for user + version Print version info help Show this help message ` @@ -30,6 +33,12 @@ func init() { } } +var ( + version = "dev" + commit = "" + date = "" +) + func main() { var configPath string flag.StringVar(&configPath, "config", "", "path to configuration file") @@ -39,15 +48,23 @@ func main() { log.Fatal("--config required") } + // read config + cfg := config.New(configPath, version) + + // init new logger + l := logger.New(cfg.Config) + // 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 { log.Fatal("could not open db connection") } - userRepo := database.NewUserRepo(nil, db) + userRepo := database.NewUserRepo(l, db) 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": username := flag.Arg(1) if username == "" { diff --git a/internal/database/database.go b/internal/database/database.go index 33c0654..9a3230f 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -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.Driver = "postgres" default: - return nil, errors.New("unsupported databse: %v", cfg.DatabaseType) + return nil, errors.New("unsupported database: %v", cfg.DatabaseType) } return db, nil