mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +02:00
use USERPROFILE instead of HOME for windows, rework paths to use
filepath.Join for better cross platform support
This commit is contained in:
@@ -5,3 +5,5 @@ src/github.com/docopt/
|
|||||||
src/github.com/mgutz/
|
src/github.com/mgutz/
|
||||||
src/github.com/op/
|
src/github.com/op/
|
||||||
src/gopkg.in/
|
src/gopkg.in/
|
||||||
|
jira
|
||||||
|
jira.exe
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -33,7 +34,7 @@ type Cli struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(opts map[string]interface{}) *Cli {
|
func New(opts map[string]interface{}) *Cli {
|
||||||
homedir := os.Getenv("HOME")
|
homedir := homedir()
|
||||||
cookieJar, _ := cookiejar.New(nil)
|
cookieJar, _ := cookiejar.New(nil)
|
||||||
endpoint, _ := opts["endpoint"].(string)
|
endpoint, _ := opts["endpoint"].(string)
|
||||||
url, _ := url.Parse(strings.TrimRight(endpoint, "/"))
|
url, _ := url.Parse(strings.TrimRight(endpoint, "/"))
|
||||||
@@ -53,7 +54,7 @@ func New(opts map[string]interface{}) *Cli {
|
|||||||
cli := &Cli{
|
cli := &Cli{
|
||||||
endpoint: url,
|
endpoint: url,
|
||||||
opts: opts,
|
opts: opts,
|
||||||
cookieFile: fmt.Sprintf("%s/.jira.d/cookies.js", homedir),
|
cookieFile: filepath.Join(homedir, ".jira.d", "cookies.js"),
|
||||||
ua: &http.Client{
|
ua: &http.Client{
|
||||||
Jar: cookieJar,
|
Jar: cookieJar,
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
@@ -214,7 +215,7 @@ func (c *Cli) GetTemplate(name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getLookedUpTemplate(name string, dflt 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)
|
return readFile(file)
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(fmt.Sprintf("/etc/go-jira/templates/%s", name)); err == nil {
|
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 {
|
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 {
|
if err := mkdir(tmpdir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,21 +6,20 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"github.com/mgutz/ansi"
|
"github.com/mgutz/ansi"
|
||||||
"gopkg.in/coryb/yaml.v2"
|
"gopkg.in/coryb/yaml.v2"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func homedir() string {
|
func homedir() string {
|
||||||
log.Errorf("GOOS: %s", runtime.GOOS)
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return os.Getenv("USERPROFILE")
|
return os.Getenv("USERPROFILE")
|
||||||
}
|
}
|
||||||
@@ -41,7 +40,6 @@ func FindParentPaths(fileName string) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
path := filepath.Join(cwd, fileName)
|
path := filepath.Join(cwd, fileName)
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
paths = append(paths, path)
|
paths = append(paths, path)
|
||||||
@@ -52,19 +50,10 @@ func FindParentPaths(fileName string) []string {
|
|||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
paths = append(paths, path)
|
paths = append(paths, path)
|
||||||
}
|
}
|
||||||
if cwd[len(cwd)-1]== filepath.Separator {
|
if cwd[len(cwd)-1] == filepath.Separator {
|
||||||
break
|
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
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user