44 "fmt"
55 "net/http"
66 "os"
7+ "path/filepath"
78
89 "github.com/go-resty/resty"
910 "github.com/labstack/gommon/log"
@@ -100,7 +101,7 @@ func Execute() {
100101
101102func init () {
102103 cobra .OnInitialize (initConfig )
103- rootCmd .PersistentFlags ().StringVarP (& configFile , "config" , "c" , "" , "config file (default is $HOME/. tunnel.yaml)" )
104+ rootCmd .PersistentFlags ().StringVarP (& configFile , "config" , "c" , "" , "config file (default is $HOME/tunnel/config .yaml)" )
104105 rootCmd .PersistentFlags ().StringVarP (& name , "name" , "n" , "" , "config name from the dashboard" )
105106 rootCmd .PersistentFlags ().BoolVarP (& tcp , "tcp" , "" , false , "tcp tunnel" )
106107 rootCmd .PersistentFlags ().BoolVarP (& tls , "tls" , "" , false , "tls tunnel" )
@@ -112,15 +113,22 @@ func initConfig() {
112113 // Use config file from the flag
113114 viper .SetConfigFile (configFile )
114115 } else {
115- // Find home directory
116- home , err := homedir .Dir ()
116+ // Create directories
117+ dir , err := homedir .Dir ()
117118 if err != nil {
118119 log .Fatalf ("failed to find the home directory: %v" , err )
119120 }
121+ root := filepath .Join (dir , ".tunnel" )
122+ if err = os .MkdirAll (filepath .Join (root , "pid" ), 0755 ); err != nil {
123+ log .Fatalf ("failed to create pid directory: %v" , err )
124+ }
125+ if err = os .MkdirAll (filepath .Join (root , "log" ), 0755 ); err != nil {
126+ log .Fatalf ("failed to create log directory: %v" , err )
127+ }
120128
121- // Search config in home directory with name ".tunnel " (without extension)
122- viper .AddConfigPath (home )
123- viper .SetConfigName (".tunnel " )
129+ // Search config in home directory with name "config " (without extension)
130+ viper .AddConfigPath (root )
131+ viper .SetConfigName ("config " )
124132 }
125133 viper .AutomaticEnv () // Read in environment variables that match
126134 viper .ReadInConfig ()
0 commit comments