File tree 3 files changed +62
-12
lines changed
3 files changed +62
-12
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ import (
17
17
"encoding/json"
18
18
"fmt"
19
19
"os"
20
- "runtime"
21
20
22
21
"github.com/aliyun/aliyun-cli/cli"
23
22
"github.com/aliyun/aliyun-cli/util"
@@ -206,14 +205,3 @@ func GetConfigPath() string {
206
205
}
207
206
return path
208
207
}
209
-
210
- func GetHomePath () string {
211
- if runtime .GOOS == "windows" {
212
- home := os .Getenv ("HOMEDRIVE" ) + os .Getenv ("HOMEPATH" )
213
- if home == "" {
214
- home = os .Getenv ("USERPROFILE" )
215
- }
216
- return home
217
- }
218
- return os .Getenv ("HOME" )
219
- }
Original file line number Diff line number Diff line change
1
+ package config
2
+
3
+ import (
4
+ "os"
5
+ "runtime"
6
+ )
7
+
8
+ func GetXDGConfigHome () string {
9
+ if xgh := os .Getenv ("XDG_CONFIG_HOME" ); xgh != "" {
10
+ return xgh
11
+ } else {
12
+ return GetHomePath () + "./config"
13
+ }
14
+ }
15
+
16
+ func GetConfigDirPath () string {
17
+ // ~/.aliyun/ 存在则是老的配置路径
18
+ // 否则:使用 XDG 规范
19
+ home := GetHomePath ()
20
+ path := home + "/.aliyun"
21
+ _ , err := os .Stat (path )
22
+ // 目录存在
23
+ if err != nil {
24
+ return path
25
+ }
26
+
27
+ return GetXDGConfigHome () + "/aliyun"
28
+ }
29
+
30
+ func GetHomePath () string {
31
+ if runtime .GOOS == "windows" {
32
+ home := os .Getenv ("HOMEDRIVE" ) + os .Getenv ("HOMEPATH" )
33
+ if home == "" {
34
+ home = os .Getenv ("USERPROFILE" )
35
+ }
36
+ return home
37
+ }
38
+ return os .Getenv ("HOME" )
39
+ }
Original file line number Diff line number Diff line change
1
+ package config
2
+
3
+ import (
4
+ "os"
5
+ "runtime"
6
+ "testing"
7
+
8
+ "github.com/stretchr/testify/assert"
9
+ )
10
+
11
+ func TestHomePath (t * testing.T ) {
12
+ if runtime .GOOS == "windows" {
13
+ assert .Equal (t , os .Getenv ("USERPROFILE" ), GetHomePath ())
14
+ } else {
15
+ assert .Equal (t , os .Getenv ("HOME" ), GetHomePath ())
16
+ }
17
+ }
18
+
19
+ func TestGetXDGConfigHome (t * testing.T ) {
20
+ if runtime .GOOS != "windows" {
21
+ assert .Equal (t , os .Getenv ("HOME" )+ "/.config" , GetXDGConfigHome ())
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments