-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_params.go
53 lines (41 loc) · 1.19 KB
/
update_params.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
package trigger
import (
"strings"
"github.com/ovh/cds/sdk"
"github.com/spf13/cobra"
)
func updateParamTriggerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update",
Short: "cds trigger update <srcproject>/<srcapp>/<srcpip>[/<env>] <destproject>/<destapp>/<desstpip>[/<destenv>] <paramName>=<paramValue> [<paramName>=<paramValue>...]",
Long: `Updates param values`,
Run: updateParamTrigger,
}
return cmd
}
func updateParamTrigger(cmd *cobra.Command, args []string) {
if len(args) <= 2 {
sdk.Exit("Wrong usage: see %s\n", cmd.Short)
}
for _, arg := range args[2:] {
splitted := strings.SplitN(arg, "=", 2)
if len(splitted) != 2 {
sdk.Exit("Invalid argument : format should be <paramName>=<paramValue> : %s\n", arg)
}
exists := false
for i := range cmdParamPipelineTrigger.Parameters {
if cmdParamPipelineTrigger.Parameters[i].Name == splitted[0] {
cmdParamPipelineTrigger.Parameters[i].Value = splitted[1]
exists = true
break
}
}
if !exists {
sdk.Exit("Error: unknown param name %s\n", splitted[0])
}
}
err := sdk.UpdateTrigger(cmdParamPipelineTrigger)
if err != nil {
sdk.Exit("Error: failed to update trigger (%s)\n", err)
}
}