GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ucloud-cli/cmd/project.go at master · ucloud/ucloud-cli

Expand file tree

/

project.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
170 lines (158 loc) · 4.67 KB
/

project.go

Copy path

File metadata and controls

170 lines (158 loc) · 4.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright © 2018 NAME HERE [email protected]
//
// 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 cmd
import (
"io"
"github.com/spf13/cobra"
"github.com/ucloud/ucloud-sdk-go/services/uaccount"
"github.com/ucloud/ucloud-cli/cmd/internal/platform"
)
// NewCmdProject ucloud project
func NewCmdProject() *cobra.Command {
var cmd = &cobra.Command{
Use: "project",
Short: "List,create,update and delete project",
Long: "List,create,update and delete project",
Example: "ucloud project",
}
out := platform.Cxt.GetWriter()
cmd.AddCommand(NewCmdProjectList(out))
cmd.AddCommand(NewCmdProjectCreate())
cmd.AddCommand(NewCmdProjectUpdate())
cmd.AddCommand(NewCmdProjectDelete())
return cmd
}
// NewCmdProjectList ucloud project list
func NewCmdProjectList(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List project",
Long: "List project",
Example: "ucloud project list",
Run: func(cmd *cobra.Command, args []string) {
listProject(out)
},
}
return cmd
}
// NewCmdProjectCreate ucloud project create
func NewCmdProjectCreate() *cobra.Command {
client := newServiceClient(uaccount.NewClient)
req := client.NewCreateProjectRequest()
cmd := &cobra.Command{
Use: "create",
Short: "Create project",
Long: "Create project",
Example: "ucloud project create --name xxx",
Run: func(cmd *cobra.Command, args []string) {
resp, err := client.CreateProject(req)
if err != nil {
platform.Cxt.PrintErr(err)
} else {
if resp.RetCode != 0 {
platform.HandleBizError(resp)
} else {
platform.Cxt.Printf("Project:%q created\n", resp.ProjectId)
}
}
},
}
req.ProjectName = cmd.Flags().String("name", "", "The name of project")
req.ParentId = cmd.Flags().String("parent-id", "", "The parent project id")
cmd.MarkFlagRequired("name")
return cmd
}
// NewCmdProjectUpdate ucloud project update
func NewCmdProjectUpdate() *cobra.Command {
client := newServiceClient(uaccount.NewClient)
req := client.NewModifyProjectRequest()
cmd := &cobra.Command{
Use: "update",
Short: "Update project name",
Long: "Update project name",
Example: "ucloud project update --id org-xxx --name new_name",
Run: func(cmd *cobra.Command, args []string) {
resp, err := client.ModifyProject(req)
if err != nil {
platform.Cxt.PrintErr(err)
} else {
if resp.RetCode != 0 {
platform.HandleBizError(resp)
} else {
platform.Cxt.Printf("Project:%s updated\n", *req.ProjectId)
}
}
},
}
req.ProjectId = cmd.Flags().String("id", "", "The project id")
req.ProjectName = cmd.Flags().String("name", "", "The new name of project")
cmd.MarkFlagRequired("name")
cmd.MarkFlagRequired("id")
return cmd
}
// NewCmdProjectDelete ucloud project delete
func NewCmdProjectDelete() *cobra.Command {
client := newServiceClient(uaccount.NewClient)
req := client.NewTerminateProjectRequest()
cmd := &cobra.Command{
Use: "delete",
Short: "Delete project",
Long: "Delete project",
Example: "ucloud project delete --id org-xxx",
Run: func(cmd *cobra.Command, args []string) {
resp, err := client.TerminateProject(req)
if err != nil {
platform.Cxt.PrintErr(err)
} else {
if resp.RetCode != 0 {
platform.HandleBizError(resp)
} else {
platform.Cxt.Printf("Project:%s deleted\n", *req.ProjectId)
}
}
},
}
req.ProjectId = cmd.Flags().String("id", "", "The project id")
cmd.MarkFlagRequired("id")
return cmd
}
func listProject(out io.Writer) error {
client := newServiceClient(uaccount.NewClient)
req := client.NewGetProjectListRequest()
resp, err := client.GetProjectList(req)
if err != nil {
return err
}
if resp.RetCode != 0 {
return platform.HandleBizError(resp)
}
if global.JSON {
return platform.PrintJSON(resp.ProjectSet, out)
}
platform.PrintTable(resp.ProjectSet, []string{"ProjectId", "ProjectName"})
return nil
}
func getProjectList() []string {
client := newServiceClient(uaccount.NewClient)
req := client.NewGetProjectListRequest()
resp, err := client.GetProjectList(req)
if err != nil {
return nil
}
list := []string{}
for _, p := range resp.ProjectSet {
list = append(list, p.ProjectId+"/"+p.ProjectName)
}
return list
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.