Paths returns config file paths that are appropriate for the operating system
( sys string, home string, envvars map[string]string, )
| 10 | // Paths returns config file paths that are appropriate for the operating |
| 11 | // system |
| 12 | func Paths( |
| 13 | sys string, |
| 14 | home string, |
| 15 | envvars map[string]string, |
| 16 | ) ([]string, error) { |
| 17 | |
| 18 | // if `CHEAT_CONFIG_PATH` is set, expand ~ and return it |
| 19 | if confpath, ok := envvars["CHEAT_CONFIG_PATH"]; ok { |
| 20 | |
| 21 | // expand ~ |
| 22 | expanded, err := homedir.Expand(confpath) |
| 23 | if err != nil { |
| 24 | return []string{}, fmt.Errorf("failed to expand ~: %v", err) |
| 25 | } |
| 26 | |
| 27 | return []string{expanded}, nil |
| 28 | } |
| 29 | |
| 30 | switch sys { |
| 31 | |
| 32 | // darwin/linux/unix |
| 33 | case "aix", "android", "darwin", "dragonfly", "freebsd", "illumos", "ios", |
| 34 | "linux", "netbsd", "openbsd", "plan9", "solaris": |
| 35 | paths := []string{} |
| 36 | |
| 37 | // don't include the `XDG_CONFIG_HOME` path if that envvar is not set |
| 38 | if xdgpath, ok := envvars["XDG_CONFIG_HOME"]; ok { |
| 39 | paths = append(paths, filepath.Join(xdgpath, "cheat", "conf.yml")) |
| 40 | } |
| 41 | |
| 42 | paths = append(paths, []string{ |
| 43 | filepath.Join(home, ".config", "cheat", "conf.yml"), |
| 44 | filepath.Join(home, ".cheat", "conf.yml"), |
| 45 | "/etc/cheat/conf.yml", |
| 46 | }...) |
| 47 | |
| 48 | return paths, nil |
| 49 | |
| 50 | // windows |
| 51 | case "windows": |
| 52 | return []string{ |
| 53 | filepath.Join(envvars["APPDATA"], "cheat", "conf.yml"), |
| 54 | filepath.Join(envvars["PROGRAMDATA"], "cheat", "conf.yml"), |
| 55 | }, nil |
| 56 | default: |
| 57 | return []string{}, fmt.Errorf("unsupported os: %s", sys) |
| 58 | } |
| 59 | } |
no outgoing calls