Skip to content

Commit dddecd2

Browse files
committed
add uhost
1 parent b2b85cf commit dddecd2

19 files changed

Lines changed: 1107 additions & 390 deletions

File tree

cmd/completion.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"strings"
2626

2727
"github.com/spf13/cobra"
28-
"github.com/ucloud/ucloud-cli/util"
28+
. "github.com/ucloud/ucloud-cli/util"
2929
)
3030

3131
// NewCmdCompletion ucloud completion
@@ -97,7 +97,7 @@ func getBashVersion() (version string, err error) {
9797
lookupBashVersion := exec.Command("bash", "-version")
9898
out, err := lookupBashVersion.Output()
9999
if err != nil {
100-
util.Tracer.AppendError(err)
100+
Cxt.PrintErr(err)
101101
fmt.Println(err)
102102
}
103103

@@ -121,10 +121,10 @@ func getBashVersion() (version string, err error) {
121121
}
122122

123123
func bashCompletion(cmd *cobra.Command) {
124-
home := util.GetHomePath()
125-
shellPath := home + "/" + util.ConfigPath + "/ucloud.sh"
124+
home := GetHomePath()
125+
shellPath := home + "/" + ConfigPath + "/ucloud.sh"
126126
cmd.GenBashCompletionFile(shellPath)
127-
fmt.Printf("Completion scripts has been written to '~/%s/ucloud.sh'\n", util.ConfigPath)
127+
fmt.Printf("Completion scripts has been written to '~/%s/ucloud.sh'\n", ConfigPath)
128128

129129
platform := runtime.GOOS
130130

@@ -136,20 +136,19 @@ func bashCompletion(cmd *cobra.Command) {
136136
}
137137

138138
func zshCompletion(cmd *cobra.Command) {
139-
home := util.GetHomePath()
140-
shellPath := home + "/" + util.ConfigPath + "/_ucloud"
139+
home := GetHomePath()
140+
shellPath := home + "/" + ConfigPath + "/_ucloud"
141141
file, err := os.Create(shellPath)
142142
if err != nil {
143-
fmt.Println(err)
144-
util.Tracer.AppendError(err)
143+
Cxt.PrintErr(err)
145144
return
146145
}
147146
defer file.Close()
148147

149148
runCompletionZsh(file, cmd)
150-
fmt.Printf("Completion scripts was written to '~/%s/_ucloud'\n", util.ConfigPath)
149+
fmt.Printf("Completion scripts was written to '~/%s/_ucloud'\n", ConfigPath)
151150

152-
scripts := fmt.Sprintf("fpath=(~/%s $fpath)\n", util.ConfigPath)
151+
scripts := fmt.Sprintf("fpath=(~/%s $fpath)\n", ConfigPath)
153152
scripts += "autoload -U +X compinit && compinit"
154153
fmt.Printf("Please append the following scripts to your ~/.zshrc\n%s\n", scripts)
155154
}

cmd/configure.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,28 @@ func NewCmdConfig() *cobra.Command {
6464
config.ConfigPublicKey()
6565
config.ConfigPrivateKey()
6666

67-
region, err := getDefaultRegion()
67+
region, zone, err := getDefaultRegion()
6868
if err != nil {
69-
Tracer.Println(err)
69+
Cxt.Println(err)
7070
return
71-
} else {
72-
config.Region = region
73-
fmt.Printf("Configured default region:%s\n", region)
7471
}
72+
config.Region = region
73+
config.Zone = zone
74+
Cxt.Printf("Configured default region:%s zone:%s\n", region, zone)
7575

76-
project, err := getDefaultProject()
76+
projectId, projectName, err := getDefaultProject()
7777
if err != nil {
78-
Tracer.Println(err)
78+
Cxt.Println(err)
7979
return
80-
} else {
81-
config.ProjectID = project
82-
fmt.Printf("Configured default project:%s\n", project)
8380
}
81+
config.ProjectID = projectId
82+
Cxt.Printf("Configured default project:%s %s\n", projectId, projectName)
8483

8584
config.SaveConfig()
8685

8786
userInfo, err := getUserInfo()
8887

89-
fmt.Printf("You are logged in as: [%s]\n", userInfo.UserEmail)
88+
Cxt.Printf("You are logged in as: [%s]\n", userInfo.UserEmail)
9089

9190
certified := isUserCertified(userInfo)
9291
if err != nil {
@@ -120,7 +119,7 @@ func NewCmdConfigList() *cobra.Command {
120119
Short: "list all settings",
121120
Long: `list all settings`,
122121
Run: func(cmd *cobra.Command, args []string) {
123-
config.ListConfig()
122+
config.ListConfig(global.json)
124123
},
125124
}
126125
return configListCmd
@@ -155,14 +154,16 @@ func NewCmdConfigSet() *cobra.Command {
155154
switch args[0] {
156155
case "region":
157156
config.Region = args[1]
157+
case "zone":
158+
config.Zone = args[1]
158159
case "project-id":
159160
config.ProjectID = args[1]
160161
case "public-key":
161162
config.PublicKey = args[1]
162163
case "private-key":
163164
config.PrivateKey = args[1]
164165
default:
165-
fmt.Println("Only public-key, private-key, region, project-id supported")
166+
Cxt.Println("Only public-key, private-key, region, zone and project-id supported")
166167
}
167168
config.SaveConfig()
168169
},

0 commit comments

Comments
 (0)