Skip to content

Commit

Permalink
feat ✨: default config dir for download dir will use xdg user dir spe…
Browse files Browse the repository at this point in the history
…cifications, close #38

Signed-off-by: Victor Hang <[email protected]>
  • Loading branch information
Banh-Canh committed Sep 30, 2024
1 parent ea881b9 commit e0d9165
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/Banh-Canh/ytui
go 1.22.6

require (
github.com/adrg/xdg v0.5.0
github.com/ktr0731/go-fuzzyfinder v0.8.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY=
cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY=
github.com/adrg/xdg v0.5.0 h1:dDaZvhMXatArP1NPHhnfaQUqWBLBsmx1h1HXQdMoFCY=
github.com/adrg/xdg v0.5.0/go.mod h1:dDdY4M4DF9Rjy4kHPeNL+ilVF+p2lK8IdM9/rTSGcI4=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
16 changes: 3 additions & 13 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"

"github.com/adrg/xdg"
"github.com/spf13/viper"
"go.uber.org/zap"

Expand All @@ -19,12 +20,7 @@ type Config struct {
func CreateDefaultConfigFile(filePath string) {
// Struct with empty channels list
// Get user's home directory
homeDir, err := os.UserHomeDir()
if err != nil {
fmt.Fprintf(os.Stderr, "error, couldn't get home directory: %v\n", err)
return
}
downloadDir := filepath.Join(homeDir, "Videos", "YouTube")
downloadDir := xdg.UserDirs.Videos
viper.SetDefault("download_dir", downloadDir)
viper.SetDefault("logLevel", "info")
viper.SetDefault("invidious", map[string]interface{}{
Expand All @@ -46,14 +42,8 @@ func CreateDefaultConfigFile(filePath string) {
}

func GetConfigDirPath() (string, error) {
// Get user's home directory
homeDir, err := os.UserHomeDir()
if err != nil {
utils.Logger.Error("Failed to get user home directory.", zap.Error(err))
return "", fmt.Errorf("failed get home directory: %v", err)
}
// Construct the directory path to the config directory
configDirPath := filepath.Join(homeDir, ".config", "ytui")
configDirPath := filepath.Join(xdg.ConfigHome, "ytui")
if err := os.MkdirAll(configDirPath, os.ModePerm); err != nil {
panic(fmt.Sprintf("Failed to create config directory: %v", err))
}
Expand Down

0 comments on commit e0d9165

Please sign in to comment.