loadConfig loads the cheat configuration for use in completion functions. It returns an error rather than exiting, since completions should degrade gracefully.
()
| 12 | // It returns an error rather than exiting, since completions should degrade |
| 13 | // gracefully. |
| 14 | func loadConfig() (config.Config, error) { |
| 15 | home, err := homedir.Dir() |
| 16 | if err != nil { |
| 17 | return config.Config{}, err |
| 18 | } |
| 19 | |
| 20 | envvars := config.EnvVars() |
| 21 | |
| 22 | confpaths, err := config.Paths(runtime.GOOS, home, envvars) |
| 23 | if err != nil { |
| 24 | return config.Config{}, err |
| 25 | } |
| 26 | |
| 27 | confpath, err := config.Path(confpaths) |
| 28 | if err != nil { |
| 29 | return config.Config{}, err |
| 30 | } |
| 31 | |
| 32 | conf, err := config.New(confpath, true) |
| 33 | if err != nil { |
| 34 | return config.Config{}, err |
| 35 | } |
| 36 | |
| 37 | return conf, nil |
| 38 | } |