Skip to content

Commit acef272

Browse files
committed
Migrate old ~/.vt.* configuration files to UserConfigDir
1 parent 6c02129 commit acef272

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

vt/main.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package main
1515

1616
import (
17+
"fmt"
1718
"os"
1819
"path"
1920

@@ -24,14 +25,34 @@ import (
2425

2526
// initConfig reads in config file and ENV variables if set.
2627
func initConfig() {
27-
2828
// Find config directory.
2929
configDir, err := os.UserConfigDir()
3030
if err == nil {
31-
viper.AddConfigPath(path.Join(configDir, "vt-cli"))
32-
}
31+
configDir = path.Join(configDir, "vt-cli")
32+
viper.AddConfigPath(configDir)
33+
34+
// Migrate old ~/.vt.* configuration files.
35+
home, err := os.UserHomeDir()
36+
if err == nil {
37+
for _, ext := range viper.SupportedExts {
38+
oldPath := path.Join(home, ".vt."+ext)
3339

34-
// Search config in home directory and current directory
40+
f, err := os.Open(oldPath)
41+
if f != nil {
42+
f.Close()
43+
}
44+
if err != nil {
45+
continue
46+
}
47+
48+
newPath := path.Join(configDir, path.Base(oldPath))
49+
os.Rename(oldPath, newPath)
50+
fmt.Printf("Migrated %s to %s\n", oldPath, newPath)
51+
}
52+
}
53+
54+
}
55+
// Search config in current directory
3556
viper.AddConfigPath(".")
3657
// Config file must be named vt + format extension (.toml, .json, etc)
3758
viper.SetConfigName("vt")

0 commit comments

Comments
 (0)