Fix Windows

This commit is contained in:
Yasuhiro Matsumoto 2021-09-29 01:33:59 +09:00
parent 768d55e5d4
commit b825e0f535
No known key found for this signature in database
GPG Key ID: 622DE34DC490584B
4 changed files with 14 additions and 12 deletions

View File

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

View File

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

View File

@ -2,7 +2,7 @@ package config
import ( import (
"fmt" "fmt"
"path" "path/filepath"
"github.com/mitchellh/go-homedir" "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 // don't include the `XDG_CONFIG_HOME` path if that envvar is not set
if xdgpath, ok := envvars["XDG_CONFIG_HOME"]; ok { 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{ paths = append(paths, []string{
path.Join(home, ".config/cheat/conf.yml"), filepath.Join(home, ".config/cheat/conf.yml"),
path.Join(home, ".cheat/conf.yml"), filepath.Join(home, ".cheat/conf.yml"),
"/etc/cheat/conf.yml", "/etc/cheat/conf.yml",
}...) }...)
return paths, nil return paths, nil
case "windows": case "windows":
return []string{ return []string{
path.Join(envvars["APPDATA"], "/cheat/conf.yml"), filepath.Join(envvars["APPDATA"], "/cheat/conf.yml"),
path.Join(envvars["PROGRAMDATA"], "/cheat/conf.yml"), filepath.Join(envvars["PROGRAMDATA"], "/cheat/conf.yml"),
}, nil }, nil
default: default:
return []string{}, fmt.Errorf("unsupported os: %s", sys) 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 // normalize the answer
ans = strings.ToLower(strings.TrimRight(ans, "\n")) ans = strings.ToLower(strings.TrimSpace(ans))
// return the appropriate response // return the appropriate response
switch ans { switch ans {