use USERPROFILE instead of HOME for windows, rework paths to use

filepath.Join for better cross platform support
This commit is contained in:
Cory Bennett
2016-06-29 06:57:59 +01:00
parent d5156d54fe
commit adcedc4855
3 changed files with 15 additions and 23 deletions
+2
View File
@@ -5,3 +5,5 @@ src/github.com/docopt/
src/github.com/mgutz/
src/github.com/op/
src/gopkg.in/
jira
jira.exe
+6 -5
View File
@@ -15,13 +15,14 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"time"
)
var (
log = logging.MustGetLogger("jira")
log = logging.MustGetLogger("jira")
VERSION string
)
@@ -33,7 +34,7 @@ type Cli struct {
}
func New(opts map[string]interface{}) *Cli {
homedir := os.Getenv("HOME")
homedir := homedir()
cookieJar, _ := cookiejar.New(nil)
endpoint, _ := opts["endpoint"].(string)
url, _ := url.Parse(strings.TrimRight(endpoint, "/"))
@@ -53,7 +54,7 @@ func New(opts map[string]interface{}) *Cli {
cli := &Cli{
endpoint: url,
opts: opts,
cookieFile: fmt.Sprintf("%s/.jira.d/cookies.js", homedir),
cookieFile: filepath.Join(homedir, ".jira.d", "cookies.js"),
ua: &http.Client{
Jar: cookieJar,
Transport: transport,
@@ -214,7 +215,7 @@ func (c *Cli) GetTemplate(name string) string {
}
func getLookedUpTemplate(name string, dflt string) string {
if file, err := FindClosestParentPath(fmt.Sprintf(".jira.d/templates/%s", name)); err == nil {
if file, err := FindClosestParentPath(filepath.Join(".jira.d", "templates", name)); err == nil {
return readFile(file)
}
if _, err := os.Stat(fmt.Sprintf("/etc/go-jira/templates/%s", name)); err == nil {
@@ -250,7 +251,7 @@ func (f NoChangesFound) Error() string {
func (c *Cli) editTemplate(template string, tmpFilePrefix string, templateData map[string]interface{}, templateProcessor func(string) error) error {
tmpdir := fmt.Sprintf("%s/.jira.d/tmp", os.Getenv("HOME"))
tmpdir := filepath.Join(homedir(), ".jira.d", "tmp")
if err := mkdir(tmpdir); err != nil {
return err
}
+7 -18
View File
@@ -6,25 +6,24 @@ import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
"github.com/mgutz/ansi"
"gopkg.in/coryb/yaml.v2"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"path/filepath"
"runtime"
"strings"
"text/template"
"time"
)
func homedir() string {
log.Errorf("GOOS: %s", runtime.GOOS)
if runtime.GOOS == "windows" {
return os.Getenv("USERPROFILE")
}
return os.Getenv("HOME")
if runtime.GOOS == "windows" {
return os.Getenv("USERPROFILE")
}
return os.Getenv("HOME")
}
func FindParentPaths(fileName string) []string {
@@ -41,7 +40,6 @@ func FindParentPaths(fileName string) []string {
}
}
path := filepath.Join(cwd, fileName)
if _, err := os.Stat(path); err == nil {
paths = append(paths, path)
@@ -52,19 +50,10 @@ func FindParentPaths(fileName string) []string {
if _, err := os.Stat(path); err == nil {
paths = append(paths, path)
}
if cwd[len(cwd)-1]== filepath.Separator {
if cwd[len(cwd)-1] == filepath.Separator {
break
}
}
// for _, part := range strings.Split(cwd, string(os.PathSeparator)) {
// if dir == "/" {
// dir = fmt.Sprintf("/%s", part)
// } else {
// dir = fmt.Sprintf("%s/%s", dir, part)
// }
// file := fmt.Sprintf("%s/%s", dir, fileName)
// }
log.Errorf("PATHS: %#v", paths)
return paths
}