@@ -75,7 +75,7 @@ func globalFlags(globalConfig *types.GlobalConfig) ([]cli.Flag, error) {
7575// the easiest way to configure. Uses some extra heuristics to help avoid having to setup
7676// OPENRUN_HOME in the env, by using the binaries parent folder as the default.
7777// On mac, looks for brew install locations also.
78- func getConfigPath (cCtx * cli.Context ) (string , string , error ) {
78+ func getConfigPath (cCtx * cli.Context ) (string , string , bool , error ) {
7979 configFile := cCtx .String (configFileFlagName )
8080 clHome := os .Getenv (types .OPENRUN_HOME )
8181 if configFile == "" {
@@ -86,21 +86,21 @@ func getConfigPath(cCtx *cli.Context) (string, string, error) {
8686 }
8787 if clHome != "" {
8888 // Found OPENRUN_HOME
89- return clHome , configFile , nil
89+ return clHome , configFile , true , nil
9090 }
9191 if configFile != "" {
9292 // OPENRUN_HOME not set and config file is set, use config dir path as OPENRUN_HOME
9393 clHome = filepath .Dir (configFile )
94- return clHome , configFile , nil
94+ return clHome , configFile , false , nil
9595 }
9696
9797 binFile , err := os .Executable ()
9898 if err != nil {
99- return "" , "" , fmt .Errorf ("unable to find executable path: %w" , err )
99+ return "" , "" , false , fmt .Errorf ("unable to find executable path: %w" , err )
100100 }
101101 binAbsolute , err := filepath .EvalSymlinks (binFile )
102102 if err != nil {
103- return "" , "" , fmt .Errorf ("unable to resolve symlink: %w" , err )
103+ return "" , "" , false , fmt .Errorf ("unable to resolve symlink: %w" , err )
104104 }
105105
106106 binParent := filepath .Dir (binAbsolute )
@@ -112,31 +112,31 @@ func getConfigPath(cCtx *cli.Context) (string, string, error) {
112112 if system .FileExists (binParentConfig ) && (strings .Contains (binParent , "openrun" ) || strings .Contains (binParent , "clhome" )) {
113113 // Config file found in parent directory of the executable, use that as path
114114 // To avoid clobbering /usr, check if the path contains the string openrun/clhome
115- return binParent , binParentConfig , nil
115+ return binParent , binParentConfig , false , nil
116116 }
117117
118118 // Running `brew --prefix` would be another option
119119 if runtime .GOOS == "darwin" { //nolint:staticcheck
120120 // brew OSX specific checks
121121 if system .FileExists ("/opt/homebrew/etc/openrun.toml" ) {
122- return "/opt/homebrew/var/openrun" , "/opt/homebrew/etc/openrun.toml" , nil
122+ return "/opt/homebrew/var/openrun" , "/opt/homebrew/etc/openrun.toml" , false , nil
123123 } else if system .FileExists ("/usr/local/etc/openrun.toml" ) {
124- return "/usr/local/var/openrun" , "/usr/local/etc/openrun.toml" , nil
124+ return "/usr/local/var/openrun" , "/usr/local/etc/openrun.toml" , false , nil
125125 }
126126 } else if runtime .GOOS == "linux" {
127127 // brew linux specific checks
128128 if system .FileExists ("/home/linuxbrew/.linuxbrew/etc/openrun.toml" ) {
129- return "/home/linuxbrew/.linuxbrew/var/openrun" , "/home/linuxbrew/.linuxbrew/etc/openrun.toml" , nil
129+ return "/home/linuxbrew/.linuxbrew/var/openrun" , "/home/linuxbrew/.linuxbrew/etc/openrun.toml" , false , nil
130130 } else if system .FileExists ("/usr/local/etc/openrun.toml" ) {
131- return "/usr/local/var/openrun" , "/usr/local/etc/openrun.toml" , nil
131+ return "/usr/local/var/openrun" , "/usr/local/etc/openrun.toml" , false , nil
132132 }
133133 }
134- return "" , "" , fmt .Errorf ("unable to find OPENRUN_HOME or config file" )
134+ return "" , "" , false , fmt .Errorf ("unable to find OPENRUN_HOME or config file" )
135135}
136136
137137func parseConfig (cCtx * cli.Context , globalConfig * types.GlobalConfig , clientConfig * types.ClientConfig , serverConfig * types.ServerConfig ) error {
138138 // Find OPENRUN_HOME and config file, update OPENRUN_HOME in env
139- clHome , filePath , err := getConfigPath (cCtx )
139+ clHome , filePath , clHomeEnvSet , err := getConfigPath (cCtx )
140140 if err != nil {
141141 return err
142142 }
@@ -149,6 +149,10 @@ func parseConfig(cCtx *cli.Context, globalConfig *types.GlobalConfig, clientConf
149149 //fmt.Fprintf(os.Stderr, "Loading config file: %s, clHome %s\n", filePath, clHome)
150150 buf , err := os .ReadFile (filePath )
151151 if err != nil {
152+ if clHomeEnvSet {
153+ fmt .Fprintf (os .Stderr , "Warning: unable to read config file %s, using default config\n " , err )
154+ return nil
155+ }
152156 return err
153157 }
154158
0 commit comments