Skip to content

Commit

Permalink
feat ✨: fix config init
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Hang <[email protected]>
  • Loading branch information
Banh-Canh committed Sep 22, 2024
1 parent 9ac0e97 commit f17881d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func initConfig() {
}
configPath := filepath.Join(configDir, "config.yaml")
viper.SetConfigFile(configPath)
config.CreateDefaultConfigFile(configPath)
if err := viper.ReadInConfig(); err != nil {
fmt.Fprintf(os.Stderr, "error, couldn't read config file: %v\n", err)
os.Exit(1)
Expand All @@ -75,8 +76,6 @@ func initConfig() {
logLevel = zapcore.InfoLevel
}
utils.InitializeLogger(logLevel, filepath.Join(configDir, "ytui.log"))
utils.Logger.Info("Initializing configuration...")
config.CreateDefaultConfigFile(configPath)
utils.Logger.Info("Initialized configuration.")
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ type Config struct {
// Creates the YAML config file
func CreateDefaultConfigFile(filePath string) {
// Struct with empty channels list
utils.Logger.Info("Config file set.", zap.String("filePath", filePath))
// Get user's home directory
homeDir, err := os.UserHomeDir()
if err != nil {
utils.Logger.Error("Failed to get home directory.", zap.Error(err))
fmt.Fprintf(os.Stderr, "error, couldn't get home directory: %v\n", err)
return
}
downloadDir := filepath.Join(homeDir, "Videos", "YouTube")
Expand Down

0 comments on commit f17881d

Please sign in to comment.