File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change 1414package main
1515
1616import (
17+ "fmt"
1718 "os"
1819 "path"
1920
@@ -24,14 +25,34 @@ import (
2425
2526// initConfig reads in config file and ENV variables if set.
2627func 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" )
You can’t perform that action at this time.
0 commit comments