8000 feat(ui,api,cli): add workflow template (#3387) · ovh/cds@6518c9c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 6518c9c

Browse files
richardltbnjjj
authored andcommitted
feat(ui,api,cli): add workflow template (#3387)
1. Description 1. Related issues close #742 1. About tests 1. Mentions @ovh/cds
1 parent 8541289 commit 6518c9c

File tree

152 files changed

+6382
-762
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+6382
-762
lines changed

cli/ask_confirm.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func AskForConfirmation(s string) bool {
1414
reader := bufio.NewReader(os.Stdin)
1515

1616
for {
17-
fmt.Printf("%s [y/n]: ", s)
17+
fmt.Printf("%s [Y/n]: ", s)
1818

1919
response, err := reader.ReadString('\n')
2020
if err != nil {
@@ -23,38 +23,58 @@ func AskForConfirmation(s string) bool {
2323

2424
response = strings.ToLower(strings.TrimSpace(response))
2525

26-
if response == "y" || response == "yes" {
26+
if response == "Y" || response == "y" || response == "yes" {
2727
return true
2828
} else if response == "n" || response == "no" {
2929
return false
30+
} else if response == "" {
31+
return true
3032
}
3133
}
3234
}
3335

3436
// MultiChoice for multiple choices question. It returns the selected option
35-
func MultiChoice(s string, opts ...string) string {
37+
func MultiChoice(s string, opts ...string) int {
3638
reader := bufio.NewReader(os.Stdin)
3739

3840
fmt.Println(s)
41+
if len(opts) == 0 {
42+
log.Fatal(fmt.Errorf("no choice available"))
43+
}
3944
for i, o := range opts {
40-
fmt.Printf("\t%s [%d]\n", o, (i + 1))
45+
fmt.Printf("\t[%d] %s\n", (i + 1), o)
4146
}
4247

4348
for {
44-
fmt.Printf("Your choice [1-%d]: ", len(opts))
45-
49+
if len(opts) > 1 {
50+
fmt.Printf("Your choice [1-%d]: ", len(opts))
51+
} else {
52+
fmt.Printf("Your choice [1]: ")
53+
}
4654
response, err := reader.ReadString('\n')
4755
if err != nil {
4856
log.Fatal(err)
4957
}
5058

51-
for i, o := range opts {
52-
trimmedResponse := strings.TrimSpace(response)
53-
n, _ := strconv.Atoi(trimmedResponse)
54-
if n == i+1 {
55-
return o
56-
}
59+
n, _ := strconv.Atoi(strings.TrimSpace(response))
60+
if 0 < n && n <= len(opts) {
61+
return n - 1
5762
}
63+
5864
fmt.Println("wrong choice")
5965
}
6066
}
67+
68+
// AskValueChoice ask for a string and returns it.
69+
func AskValueChoice(s string) string {
70+
reader := bufio.NewReader(os.Stdin)
71+
72+
fmt.Printf("%s", s)
73+
74+
response, err := reader.ReadString('\n')
75+
if err != nil {
76+
log.Fatal(err)
77+
}
78+
79+
return strings.TrimSpace(response)
80+
}

cli/cdsctl/admin_grpc_plugin.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@ func adminPluginsAddBinaryFunc(v cli.Values) error {
187187
return fmt.Errorf("unable to compute sha512sum for file %s: %v", v.GetString("filename"), err)
188188
}
189189

190-
if err := client.PluginAddBinary(p, &desc); err != nil {
191-
return err
192-
}
193-
194-
return nil
190+
return client.PluginAddBinary(p, &desc)
195191
}
196192

197193
var adminPluginsDocCmd = cli.Command{

cli/cdsctl/admin_platform.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ func adminPlatformModelImportRun(v cli.Values) error {
110110
//Try to load the model to know if we have to add it or update it
111111
model, _ := client.PlatformModelGet(m.Name)
112112
if model.ID == 0 { // If the model has not been found
113-
if err := client.PlatformModelAdd(m); err != nil {
114-
return err
115-
}
116-
return nil
113+
return client.PlatformModelAdd(m)
117114
}
118115

119116
return client.PlatformModelUpdate(m)
@@ -130,8 +127,5 @@ var adminPlatformModelDeleteCmd = cli.Command{
130127
}
131128

132129
func adminPlatformModelDeleteRun(v cli.Values) error {
133-
if err := client.PlatformModelDelete(v.GetString("name")); err != nil {
134-
return err
135-
}
136-
return nil
130+
return client.PlatformModelDelete(v.GetString("name"))
137131
}

0 commit comments

Comments
 (0)
0