1
1
package main
2
2
3
3
import (
4
+ "io/ioutil"
5
+ "os"
6
+
7
+ "github.com/pkg/errors"
4
8
"github.com/spf13/cobra"
5
9
6
10
"github.com/ovh/cds/cli"
@@ -32,8 +36,17 @@ var projectVariableCreateCmd = cli.Command{
32
36
Args : []cli.Arg {
33
37
{Name : "variable-name" },
34
38
{Name : "variable-type" },
39
+ },
40
+ OptionalArgs : []cli.Arg {
35
41
{Name : "variable-value" },
36
42
},
43
+ Flags : []cli.Flag {
44
+ {
45
+ Name : "stdin" ,
46
+ Usage : "read the variable value from stdin" ,
47
+ Type : cli .FlagBool ,
48
+ },
49
+ },
37
50
}
38
51
39
52
func projectCreateVariableRun (v cli.Values ) error {
@@ -42,6 +55,19 @@ func projectCreateVariableRun(v cli.Values) error {
42
55
Type : v .GetString ("variable-type" ),
43
56
Value : v .GetString ("variable-value" ),
44
57
}
58
+
59
+ if variable .Value == "" && v .GetBool ("stdin" ) {
60
+ btes , err := ioutil .ReadAll (os .Stdin )
61
+ if err != nil {
62
+ return err
63
+ }
64
+ variable .Value = string (btes )
65
+ }
66
+
67
+ if variable .Value == "" {
68
+ return errors .New ("missing value" )
69
+ }
70
+
45
71
return client .ProjectVariableCreate (v .GetString (_ProjectKey ), variable )
46
72
}
47
73
@@ -101,8 +127,17 @@ var projectVariableUpdateCmd = cli.Command{
101
127
{Name : "variable-oldname" },
102
128
{Name : "variable-name" },
103
129
{Name : "variable-type" },
130
+ },
131
+ OptionalArgs : []cli.Arg {
104
132
{Name : "variable-value" },
105
133
},
134
+ Flags : []cli.Flag {
135
+ {
136
+ Name : "stdin" ,
137
+ Usage : "read the variable value from stdin" ,
138
+ Type : cli .FlagBool ,
139
+ },
140
+ },
106
141
}
107
142
108
143
func projectUpdateVariableRun (v cli.Values ) error {
@@ -113,5 +148,18 @@ func projectUpdateVariableRun(v cli.Values) error {
113
148
variable .Name = v .GetString ("variable-name" )
114
149
variable .Type = v .GetString ("variable-type" )
115
150
variable .Value = v .GetString ("variable-value" )
151
+
152
+ if variable .Value == "" && v .GetBool ("stdin" ) {
153
+ btes , err := ioutil .ReadAll (os .Stdin )
154
+ if err != nil {
155
+ return err
156
+ }
157
+ variable .Value = string (btes )
158
+ }
159
+
160
+ if variable .Value == "" {
161
+ return errors .New ("missing value" )
162
+ }
163
+
116
164
return client .ProjectVariableUpdate (v .GetString (_ProjectKey ), variable )
117
165
}
0 commit comments