FindOrCreateConfigPath returns the first path that contains a config file or creates one in the primary default path if it doesn't exist
()
| 121 | // FindOrCreateConfigPath returns the first path that contains a config file |
| 122 | // or creates one in the primary default path if it doesn't exist |
| 123 | func FindOrCreateConfigPath() string { |
| 124 | path := FindDefaultConfigPath() |
| 125 | |
| 126 | if path == "" { |
| 127 | // create the default directory if it doesn't exist |
| 128 | path = DefaultConfigPath() |
| 129 | if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { |
| 130 | return "" |
| 131 | } |
| 132 | |
| 133 | // write a new config file out |
| 134 | file, err := os.Create(path) |
| 135 | if err != nil { |
| 136 | return "" |
| 137 | } |
| 138 | defer file.Close() |
| 139 | |
| 140 | logDir := DefaultLogDirectory() |
| 141 | _ = os.MkdirAll(logDir, os.ModePerm) // try and create it. Doesn't matter if it succeed or not, only byproduct will be no logs |
| 142 | |
| 143 | c := Root{ |
| 144 | LogDirectory: logDir, |
| 145 | } |
| 146 | if err := yaml.NewEncoder(file).Encode(&c); err != nil { |
| 147 | return "" |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return path |
| 152 | } |
| 153 | |
| 154 | // ValidateUnixSocket ensures --unix-socket param is used exclusively |
| 155 | // i.e. it fails if a user specifies both --url and --unix-socket |
no test coverage detected