Skip to content

Commit

Permalink
use USERPROFILE instead of HOME for windows, rework paths to use
Browse files Browse the repository at this point in the history
filepath.Join for better cross platform support
  • Loading branch information
coryb committed Jun 29, 2016
1 parent d5156d5 commit adcedc4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ src/github.com/docopt/
src/github.com/mgutz/
src/github.com/op/
src/gopkg.in/
jira
jira.exe
11 changes: 6 additions & 5 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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, "/"))
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 7 additions & 18 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit adcedc4

Please sign in to comment.