/
hello.go
102 lines (90 loc) · 3.68 KB
/
hello.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 1999-2019 Alibaba Group Holding Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"fmt"
"os"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"github.com/aliyun/aliyun-cli/cli"
)
type Region struct {
RegionId string
LocalName string
}
func GetRegions(ctx *cli.Context, profile *Profile) ([]Region, error) {
client, err := profile.GetClient(ctx)
regions := make([]Region, 0)
if err != nil {
return regions, err
}
request := ecs.CreateDescribeRegionsRequest()
response := ecs.CreateDescribeRegionsResponse()
if vendorEnv, ok := os.LookupEnv("ALIBABA_CLOUD_VENDOR"); ok {
client.AppendUserAgent("vendor", vendorEnv)
}
client.AppendUserAgent("Aliyun-CLI", cli.GetVersion())
err = client.DoAction(request, response)
for _, region := range response.Regions.Region {
regions = append(regions, Region{
RegionId: region.RegionId,
LocalName: region.LocalName,
})
}
return regions, nil
}
func DoHello(ctx *cli.Context, profile *Profile) {
w := ctx.Writer()
client, err := profile.GetClient(ctx)
if err != nil {
cli.Println(w, "-----------------------------------------------")
cli.Println(w, "!!! Configure Failed please configure again !!!")
cli.Println(w, "-----------------------------------------------")
cli.Println(w, err)
cli.Println(w, "-----------------------------------------------")
cli.Println(w, "!!! Configure Failed please configure again !!!")
cli.Println(w, "-----------------------------------------------")
return
}
request := ecs.CreateDescribeRegionsRequest()
response := ecs.CreateDescribeRegionsResponse()
if vendorEnv, ok := os.LookupEnv("ALIBABA_CLOUD_VENDOR"); ok {
client.AppendUserAgent("vendor", vendorEnv)
}
client.AppendUserAgent("Aliyun-CLI", cli.GetVersion())
err = client.DoAction(request, response)
if err != nil {
cli.Println(w, "-----------------------------------------------")
cli.Println(w, "!!! Configure Failed please configure again !!!")
cli.Println(w, "-----------------------------------------------")
cli.Println(w, err)
cli.Println(w, "-----------------------------------------------")
cli.Println(w, "!!! Configure Failed please configure again !!!")
cli.Println(w, "-----------------------------------------------")
return
}
fmt.Println(icon)
}
var icon = string(`
Configure Done!!!
..............888888888888888888888 ........=8888888888888888888D=..............
...........88888888888888888888888 ..........D8888888888888888888888I...........
.........,8888888888888ZI: ...........................=Z88D8888888888D..........
.........+88888888 ..........................................88888888D..........
.........+88888888 .......Welcome to use Alibaba Cloud.......O8888888D..........
.........+88888888 ............. ************* ..............O8888888D..........
.........+88888888 .... Command Line Interface(Reloaded) ....O8888888D..........
.........+88888888...........................................88888888D..........
..........D888888888888DO+. ..........................?ND888888888888D..........
...........O8888888888888888888888...........D8888888888888888888888=...........
............ .:D8888888888888888888.........78888888888888888888O ..............`)