Merge pull request #639 from mattn/fix-windows

Fix Windows
This commit is contained in:
Chris Allen Lane 2021-10-09 10:10:39 -04:00 committed by GitHub
commit 23b6928874
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 12 deletions

View file

@ -1,3 +1,4 @@
//go:build ignore
// +build ignore
// This script embeds `docopt.txt and `conf.yml` into the binary during at
@ -5,13 +6,11 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
)
@ -52,10 +51,10 @@ func main() {
for _, file := range files {
// delete the outfile
os.Remove(path.Join(root, file.Out))
os.Remove(filepath.Join(root, file.Out))
// read the static template
bytes, err := ioutil.ReadFile(path.Join(root, file.In))
bytes, err := ioutil.ReadFile(filepath.Join(root, file.In))
if err != nil {
log.Fatal(err)
}
@ -64,7 +63,7 @@ func main() {
data := template(file.Method, string(bytes))
// write the file to the specified outpath
spath := path.Join(root, file.Out)
spath := filepath.Join(root, file.Out)
err = ioutil.WriteFile(spath, []byte(data), 0644)
if err != nil {
log.Fatal(err)

View file

@ -45,6 +45,9 @@ func main() {
envvars := map[string]string{}
for _, e := range os.Environ() {
pair := strings.SplitN(e, "=", 2)
if runtime.GOOS == "windows" {
pair[0] = strings.ToUpper(pair[0])
}
envvars[pair[0]] = pair[1]
}

View file

@ -2,7 +2,7 @@ package config
import (
"fmt"
"path"
"path/filepath"
"github.com/mitchellh/go-homedir"
)
@ -33,20 +33,20 @@ func Paths(
// don't include the `XDG_CONFIG_HOME` path if that envvar is not set
if xdgpath, ok := envvars["XDG_CONFIG_HOME"]; ok {
paths = append(paths, path.Join(xdgpath, "/cheat/conf.yml"))
paths = append(paths, filepath.Join(xdgpath, "/cheat/conf.yml"))
}
paths = append(paths, []string{
path.Join(home, ".config/cheat/conf.yml"),
path.Join(home, ".cheat/conf.yml"),
filepath.Join(home, ".config/cheat/conf.yml"),
filepath.Join(home, ".cheat/conf.yml"),
"/etc/cheat/conf.yml",
}...)
return paths, nil
case "windows":
return []string{
path.Join(envvars["APPDATA"], "/cheat/conf.yml"),
path.Join(envvars["PROGRAMDATA"], "/cheat/conf.yml"),
filepath.Join(envvars["APPDATA"], "/cheat/conf.yml"),
filepath.Join(envvars["PROGRAMDATA"], "/cheat/conf.yml"),
}, nil
default:
return []string{}, fmt.Errorf("unsupported os: %s", sys)

View file

@ -23,7 +23,7 @@ func Prompt(prompt string, def bool) (bool, error) {
}
// normalize the answer
ans = strings.ToLower(strings.TrimRight(ans, "\n"))
ans = strings.ToLower(strings.TrimSpace(ans))
// return the appropriate response
switch ans {