@@ -27,7 +27,9 @@ import (
2727 "github.com/spf13/viper"
2828)
2929
30- // Init initialize defaults and read the configuration file
30+ // Init initialize defaults and read the configuration file.
31+ // Please note the logging system hasn't been configured yet,
32+ // so logging shouldn't be used here.
3133func Init (configPath string ) {
3234 // Config file metadata
3335 viper .SetConfigName ("arduino-cli" )
@@ -38,7 +40,6 @@ func Init(configPath string) {
3840 }
3941
4042 // Add paths where to search for a config file
41- logrus .Infof ("Checking for config file in: %s" , configPath )
4243 viper .AddConfigPath (configPath )
4344
4445 // Bind env vars
@@ -67,9 +68,9 @@ func Init(configPath string) {
6768
6869 // Attempt to read config file
6970 if err := viper .ReadInConfig (); err != nil {
70- if _ , ok := err .(viper. ConfigFileNotFoundError ); ok {
71- logrus . Info ( "Config file not found, using default values" )
72- } else {
71+ // ConfigFileNotFoundError is acceptable, anything else
72+ // should be reported to the user
73+ if _ , ok := err .(viper. ConfigFileNotFoundError ); ! ok {
7374 feedback .Errorf ("Error reading config file: %v" , err )
7475 }
7576 }
@@ -79,7 +80,7 @@ func Init(configPath string) {
7980func getDefaultArduinoDataDir () string {
8081 userHomeDir , err := os .UserHomeDir ()
8182 if err != nil {
82- logrus .Errorf ("Unable to get user home dir: %v" , err )
83+ feedback .Errorf ("Unable to get user home dir: %v" , err )
8384 return "."
8485 }
8586
@@ -91,7 +92,7 @@ func getDefaultArduinoDataDir() string {
9192 case "windows" :
9293 localAppDataPath , err := win32 .GetLocalAppDataFolder ()
9394 if err != nil {
94- logrus .Errorf ("Unable to get Local App Data Folder: %v" , err )
95+ feedback .Errorf ("Unable to get Local App Data Folder: %v" , err )
9596 return "."
9697 }
9798 return filepath .Join (localAppDataPath , "Arduino15" )
@@ -104,7 +105,7 @@ func getDefaultArduinoDataDir() string {
104105func getDefaultSketchbookDir () string {
105106 userHomeDir , err := os .UserHomeDir ()
106107 if err != nil {
107- logrus .Errorf ("Unable to get user home dir: %v" , err )
108+ feedback .Errorf ("Unable to get user home dir: %v" , err )
108109 return "."
109110 }
110111
@@ -116,7 +117,7 @@ func getDefaultSketchbookDir() string {
116117 case "windows" :
117118 documentsPath , err := win32 .GetDocumentsFolder ()
118119 if err != nil {
119- logrus .Errorf ("Unable to get Documents Folder: %v" , err )
120+ feedback .Errorf ("Unable to get Documents Folder: %v" , err )
120121 return "."
121122 }
122123 return filepath .Join (documentsPath , "Arduino" )
@@ -138,18 +139,17 @@ func IsBundledInDesktopIDE() bool {
138139 logrus .Info ("Checking if CLI is Bundled into the IDE" )
139140 executable , err := os .Executable ()
140141 if err != nil {
141- logrus . WithError ( err ). Warn ( "Cannot get executable path" )
142+ feedback . Errorf ( "Cannot get executable path: %v" , err )
142143 return viper .GetBool ("IDE.Bundled" )
143144 }
144145
145146 executablePath , err := filepath .EvalSymlinks (executable )
146147 if err != nil {
147- logrus . WithError ( err ). Warn ( "Cannot get executable path" )
148+ feedback . Errorf ( "Cannot get executable path: %v" , err )
148149 return viper .GetBool ("IDE.Bundled" )
149150 }
150151
151152 ideDir := filepath .Dir (executablePath )
152- logrus .Info ("Candidate IDE Directory: " , ideDir )
153153
154154 // We check an arbitrary number of folders that are part of the IDE
155155 // install tree
@@ -166,7 +166,6 @@ func IsBundledInDesktopIDE() bool {
166166 }
167167
168168 if test == "portable" {
169- logrus .Info ("IDE is portable" )
170169 viper .Set ("IDE.Portable" , true )
171170 }
172171 }
0 commit comments