Skip to content

Commit 08672be

Browse files
authored
Merge pull request #62 from ucloud/fix/init-cmd
cmd/init: fix bug and update description
2 parents 452c503 + be65122 commit 08672be

6 files changed

Lines changed: 23 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## 0.1.38 (2021-07-07)
1+
## 0.1.39 (2022-06-13)
2+
3+
* fix init failure when user donot have a default project in ucloud console.
4+
* update the description of init.
5+
6+
## 0.1.38 (2022-04-27)
27

38
* fix build failure when using go 1.18 on darwin_arm64. ([golang/go#49219](https://github.com/golang/go/issues/49219))
49

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export VERSION=0.1.38
1+
export VERSION=0.1.39
22
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
33

44
.PHONY : install

base/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const DefaultBaseURL = "https://api.ucloud.cn/"
3939
const DefaultProfile = "default"
4040

4141
//Version 版本号
42-
const Version = "0.1.38"
42+
const Version = "0.1.39"
4343

4444
var UserAgent = fmt.Sprintf("UCloud-CLI/%s", Version)
4545

cmd/configure.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package cmd
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"strconv"
2021

@@ -26,7 +27,7 @@ import (
2627
"github.com/ucloud/ucloud-cli/base"
2728
)
2829

29-
const configDesc = `Public-key and private-key could be acquired from https://console.ucloud.cn/uapi/apikey.`
30+
const configDesc = `Public-key and private-key could be acquired from https://console.ucloud.cn/uaccount/api_manage`
3031

3132
const helloUcloud = `
3233
_ _ _ _ _ _ _____ _ _
@@ -72,12 +73,16 @@ func NewCmdInit() *cobra.Command {
7273
fmt.Printf("Configured default region:%s zone:%s\n", region.DefaultRegion, region.DefaultZone)
7374

7475
projectID, projectName, err := getDefaultProjectWithConfig(base.ConfigIns)
75-
if err != nil {
76+
if err != nil && !errors.Is(err, errNoDefaultProject) {
7677
base.HandleError(err)
7778
return
7879
}
79-
base.ConfigIns.ProjectID = projectID
80-
fmt.Printf("Configured default project:%s %s\n", projectID, projectName)
80+
if projectID != "" && projectName != "" {
81+
base.ConfigIns.ProjectID = projectID
82+
fmt.Printf("Configured default project:%s %s\n", projectID, projectName)
83+
} else {
84+
fmt.Println("No default project, skip.")
85+
}
8186
base.ConfigIns.Timeout = base.DefaultTimeoutSec
8287
base.ConfigIns.BaseURL = base.DefaultBaseURL
8388
base.ConfigIns.MaxRetryTimes = sdk.Int(base.DefaultMaxRetryTimes)

cmd/region.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cmd
1616

1717
import (
1818
"encoding/json"
19+
"errors"
1920
"fmt"
2021
"io"
2122
"io/ioutil"
@@ -164,6 +165,8 @@ func getZoneList(region string) []string {
164165
return list
165166
}
166167

168+
var errNoDefaultProject = errors.New("No default project")
169+
167170
func getDefaultProject() (string, string, error) {
168171
req := base.BizClient.NewGetProjectListRequest()
169172

@@ -176,8 +179,9 @@ func getDefaultProject() (string, string, error) {
176179
return project.ProjectId, project.ProjectName, nil
177180
}
178181
}
179-
return "", "", fmt.Errorf("No default project")
182+
return "", "", errNoDefaultProject
180183
}
184+
181185
func getDefaultProjectWithConfig(cfg *base.AggConfig) (string, string, error) {
182186
bc, err := base.GetBizClient(cfg)
183187
if err != nil {
@@ -194,7 +198,7 @@ func getDefaultProjectWithConfig(cfg *base.AggConfig) (string, string, error) {
194198
return project.ProjectId, project.ProjectName, nil
195199
}
196200
}
197-
return "", "", fmt.Errorf("No default project")
201+
return "", "", errNoDefaultProject
198202
}
199203

200204
func fetchProjectWithConfig(cfg *base.AggConfig) (map[string]bool, error) {

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
4242
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4343
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
4444
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
45-
github.com/ucloud/ucloud-sdk-go v0.21.20 h1:lkjf+jCaqLMY05fLLGFvvN3n/SQhgacU+XLlIHOaLmQ=
46-
github.com/ucloud/ucloud-sdk-go v0.21.20/go.mod h1:dyLmFHmUfgb4RZKYQP9IArlvQ2pxzFthfhwxRzOEPIw=
4745
github.com/ucloud/ucloud-sdk-go v0.21.21 h1:c4UtP8dR3vfYY9bzxaOtRc3L1jdv9R7GteomTqI3vV8=
4846
github.com/ucloud/ucloud-sdk-go v0.21.21/go.mod h1:dyLmFHmUfgb4RZKYQP9IArlvQ2pxzFthfhwxRzOEPIw=
4947
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
@@ -57,7 +55,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
5755
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5856
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5957
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
60-
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
6158
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6259
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
6360
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)