Skip to content

Commit e968d7f

Browse files
committed
fix: #6
1 parent 078ff0b commit e968d7f

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

wallhaven/cli.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ func Download(cmd *cobra.Command, args []string) error {
7979
return err
8080
}
8181

82-
fmt.Printf("[download] %v", v)
82+
fmt.Printf("[download] %s", v)
8383
}
8484

8585
return nil
8686
}
8787

8888
func Edit(cmd *cobra.Command, args []string) error {
89-
command := exec.Command(config.Editor, configPath)
89+
command := exec.Command(config.Editor, configFile)
9090

9191
command.Stdin = os.Stdin
9292
command.Stdout = os.Stdout
@@ -137,7 +137,7 @@ func Collection(cmd *cobra.Command, args []string) error {
137137
return err
138138
}
139139

140-
fmt.Printf("[download] %v\r\n", v.ImageID)
140+
fmt.Printf("[download] %s\r\n", v.ImageID)
141141
}
142142
if images.Meta.LastPage > page {
143143
page++
@@ -260,7 +260,7 @@ func Preview(cmd *cobra.Command, args []string) error {
260260
command.Stderr = os.Stderr
261261

262262
if err := command.Run(); err != nil {
263-
return fmt.Errorf("failed to execute command: %v", err)
263+
return fmt.Errorf("failed to execute command: %s", err)
264264
}
265265

266266
if file != "" {

wallhaven/main.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
var config Config
17-
var configPath string
17+
var configFile string
1818
var re = regexp.MustCompile(`\(([^)]+)\)`)
1919

2020
func init() {
@@ -25,9 +25,14 @@ func init() {
2525
return
2626
}
2727

28-
configPath = filepath.Join(usr.HomeDir, ".config", "wallhaven-cli", "config.toml")
28+
configPath := filepath.Join(usr.HomeDir, ".config", "wallhaven-cli")
29+
configFile = filepath.Join(configPath, "config.toml")
2930

30-
if _, decodeError := toml.DecodeFile(configPath, &config); decodeError != nil {
31+
os.MkdirAll(configPath, os.ModePerm)
32+
os.MkdirAll(config.TempFolder, os.ModePerm)
33+
os.MkdirAll(config.SaveFolder, os.ModePerm)
34+
35+
if _, decodeError := toml.DecodeFile(configFile, &config); decodeError != nil {
3136
config = Config{
3237
Editor: "nano",
3338
SaveFolder: filepath.Join(usr.HomeDir, "Pictures", "wallpapers"),
@@ -53,23 +58,14 @@ func init() {
5358
return
5459
}
5560

56-
if err := os.WriteFile(configPath, encodedData, os.ModePerm); err != nil {
61+
WriteError := os.WriteFile(configFile, encodedData, os.ModePerm)
62+
if WriteError != nil {
5763
fmt.Print(err)
5864
os.Exit(1)
5965
}
6066
}
61-
62-
if err := os.MkdirAll(config.TempFolder, os.ModePerm); err != nil {
63-
fmt.Print(err)
64-
os.Exit(1)
65-
}
66-
67-
if err := os.MkdirAll(config.SaveFolder, os.ModePerm); err != nil {
68-
fmt.Print(err)
69-
os.Exit(1)
70-
}
7167
} else {
72-
log.Fatalf("Your os isn't supported: %v", runtime.GOOS)
68+
log.Fatalf("Your os isn't supported: %s", runtime.GOOS)
7369
return
7470
}
7571
}

0 commit comments

Comments
 (0)