Skip to content

Commit 5aad487

Browse files
ref(*): rewrite to use path/filepath for better OS compatibility
1 parent af43972 commit 5aad487

7 files changed

Lines changed: 24 additions & 22 deletions

File tree

cmd/keys.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"io/ioutil"
6-
"path"
6+
"path/filepath"
77
"strconv"
88
"strings"
99

@@ -78,7 +78,7 @@ func KeyAdd(keyLocation string) error {
7878
return err
7979
}
8080

81-
fmt.Printf("Uploading %s to deis...", path.Base(key.Name))
81+
fmt.Printf("Uploading %s to deis...", filepath.Base(key.Name))
8282

8383
if _, err = keys.New(c, key.ID, key.Public); err != nil {
8484
fmt.Println()
@@ -99,7 +99,7 @@ func chooseKey() (api.KeyCreateRequest, error) {
9999
fmt.Println("Found the following SSH public keys:")
100100

101101
for i, key := range keys {
102-
fmt.Printf("%d) %s %s\n", i+1, path.Base(key.Name), key.ID)
102+
fmt.Printf("%d) %s %s\n", i+1, filepath.Base(key.Name), key.ID)
103103
}
104104

105105
fmt.Println("0) Enter path to pubfile (or use keys:add <key_path>)")
@@ -132,7 +132,7 @@ func chooseKey() (api.KeyCreateRequest, error) {
132132
}
133133

134134
func listKeys() ([]api.KeyCreateRequest, error) {
135-
folder := path.Join(client.FindHome(), ".ssh")
135+
folder := filepath.Join(client.FindHome(), ".ssh")
136136
files, err := ioutil.ReadDir(folder)
137137

138138
if err != nil {
@@ -142,8 +142,8 @@ func listKeys() ([]api.KeyCreateRequest, error) {
142142
var keys []api.KeyCreateRequest
143143

144144
for _, file := range files {
145-
if path.Ext(file.Name()) == ".pub" {
146-
key, err := getKey(path.Join(folder, file.Name()))
145+
if filepath.Ext(file.Name()) == ".pub" {
146+
key, err := getKey(filepath.Join(folder, file.Name()))
147147

148148
if err == nil {
149149
keys = append(keys, key)
@@ -163,7 +163,7 @@ func getKey(filename string) (api.KeyCreateRequest, error) {
163163
return api.KeyCreateRequest{}, err
164164
}
165165

166-
backupID := strings.Split(path.Base(filename), ".")[0]
166+
backupID := strings.Split(filepath.Base(filename), ".")[0]
167167
keyInfo, err := ssh.ParsePubKey(backupID, keyContents)
168168
if err != nil {
169169
return api.KeyCreateRequest{}, fmt.Errorf("%s is not a valid ssh key", filename)

cmd/keys_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cmd
33
import (
44
"io/ioutil"
55
"os"
6-
"path"
6+
"path/filepath"
77
"reflect"
88
"testing"
99

@@ -54,7 +54,7 @@ func TestGetKeyNoComment(t *testing.T) {
5454
toWrite := []byte("ssh-rsa abc")
5555

5656
expected := api.KeyCreateRequest{
57-
ID: path.Base(file.Name()),
57+
ID: filepath.Base(file.Name()),
5858
Public: string(toWrite),
5959
Name: file.Name(),
6060
}
@@ -83,7 +83,7 @@ func TestListKeys(t *testing.T) {
8383

8484
os.Setenv("HOME", name)
8585

86-
folder := path.Join(name, ".ssh")
86+
folder := filepath.Join(name, ".ssh")
8787

8888
if err = os.Mkdir(folder, 0755); err != nil {
8989
t.Fatal(err)
@@ -96,17 +96,17 @@ func TestListKeys(t *testing.T) {
9696
{
9797
ID: "test@example.com",
9898
Public: string(toWrite),
99-
Name: path.Join(folder, fileNames[0]),
99+
Name: filepath.Join(folder, fileNames[0]),
100100
},
101101
{
102102
ID: "test@example.com",
103103
Public: string(toWrite),
104-
Name: path.Join(folder, fileNames[1]),
104+
Name: filepath.Join(folder, fileNames[1]),
105105
},
106106
}
107107

108108
for _, file := range fileNames {
109-
if err = ioutil.WriteFile(path.Join(folder, file), toWrite, 0775); err != nil {
109+
if err = ioutil.WriteFile(filepath.Join(folder, file), toWrite, 0775); err != nil {
110110
t.Fatal(err)
111111
}
112112
}

controller/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"net/http"
88
"net/url"
99
"os"
10-
"path"
10+
"path/filepath"
1111
)
1212

1313
// Client oversees the interaction between the client and controller
@@ -94,7 +94,7 @@ func (c Client) Save() error {
9494
return err
9595
}
9696

97-
if err = os.MkdirAll(path.Join(FindHome(), "/.deis/"), 0775); err != nil {
97+
if err = os.MkdirAll(filepath.Join(FindHome(), "/.deis/"), 0775); err != nil {
9898
return err
9999
}
100100

controller/client/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"io/ioutil"
55
"net/url"
66
"os"
7-
"path"
7+
"path/filepath"
88
"testing"
99
)
1010

@@ -19,12 +19,12 @@ func createTempProfile(contents string) error {
1919

2020
os.Unsetenv("DEIS_PROFILE")
2121
os.Setenv("HOME", name)
22-
folder := path.Join(name, "/.deis/")
22+
folder := filepath.Join(name, ".deis")
2323
if err = os.Mkdir(folder, 0755); err != nil {
2424
return err
2525
}
2626

27-
if err = ioutil.WriteFile(path.Join(folder, "client.json"), []byte(contents), 0775); err != nil {
27+
if err = ioutil.WriteFile(filepath.Join(folder, "client.json"), []byte(contents), 0775); err != nil {
2828
return err
2929
}
3030

controller/client/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package client
33
import (
44
"fmt"
55
"os"
6-
"path"
6+
"path/filepath"
77

88
"github.com/deis/workflow-cli/version"
99
)
@@ -15,7 +15,7 @@ func locateSettingsFile() string {
1515
filename = "client"
1616
}
1717

18-
return path.Join(FindHome(), ".deis", filename+".json")
18+
return filepath.Join(FindHome(), ".deis", filename+".json")
1919
}
2020

2121
func checkAPICompatibility(serverAPIVersion string) {

controller/client/utils_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux darwin
2+
13
package client
24

35
import (

pkg/git/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"io/ioutil"
77
"os"
88
"os/exec"
9-
"path"
9+
"path/filepath"
1010
"strings"
1111
)
1212

@@ -77,7 +77,7 @@ func DetectAppName(host string) (string, error) {
7777
// Don't return an error if remote can't be found, return directory name instead.
7878
if err != nil {
7979
dir, err := os.Getwd()
80-
return strings.ToLower(path.Base(dir)), err
80+
return strings.ToLower(filepath.Base(dir)), err
8181
}
8282

8383
ss := strings.Split(remote, "/")

0 commit comments

Comments
 (0)