@@ -39,6 +39,11 @@ type (
39
39
}
40
40
)
41
41
42
+ var gitProvidersByName = map [string ]model.GitProviders {
43
+ "github" : model .GitProvidersGithub ,
44
+ "gitlab" : model .GitProvidersGitlab ,
45
+ }
46
+
42
47
func NewIntegrationCommand () * cobra.Command {
43
48
var (
44
49
runtime string
@@ -60,6 +65,8 @@ func NewIntegrationCommand() *cobra.Command {
60
65
61
66
cmd .AddCommand (NewGitIntegrationCommand (& client ))
62
67
68
+ cmd .Hidden = true // hide this command for now
69
+
63
70
return cmd
64
71
}
65
72
@@ -142,24 +149,25 @@ func RunGitIntegrationListCommand(ctx context.Context, client sdk.AppProxyAPI, f
142
149
143
150
func NewGitIntegrationGetCommand (client * sdk.AppProxyAPI ) * cobra.Command {
144
151
var (
145
- format string
152
+ format string
153
+ integration * string
146
154
)
147
155
148
156
allowedFormats := []string {"yaml" , "yml" , "json" }
149
157
150
158
cmd := & cobra.Command {
151
- Use : "get NAME" ,
159
+ Use : "get [ NAME] " ,
152
160
Short : "Retrieve a git integration" ,
153
161
RunE : func (cmd * cobra.Command , args []string ) error {
154
- if len (args ) < 1 {
155
- return fmt . Errorf ( "missing integration name" )
162
+ if len (args ) > 0 {
163
+ integration = & args [ 0 ]
156
164
}
157
165
158
166
if err := verifyOutputFormat (format , allowedFormats ... ); err != nil {
159
167
return err
160
168
}
161
169
162
- return RunGitIntegrationGetCommand (cmd .Context (), * client , args [ 0 ] , format )
170
+ return RunGitIntegrationGetCommand (cmd .Context (), * client , integration , format )
163
171
},
164
172
}
165
173
@@ -168,7 +176,7 @@ func NewGitIntegrationGetCommand(client *sdk.AppProxyAPI) *cobra.Command {
168
176
return cmd
169
177
}
170
178
171
- func RunGitIntegrationGetCommand (ctx context.Context , client sdk.AppProxyAPI , name , format string ) error {
179
+ func RunGitIntegrationGetCommand (ctx context.Context , client sdk.AppProxyAPI , name * string , format string ) error {
172
180
gi , err := client .GitIntegrations ().Get (ctx , name )
173
181
if err != nil {
174
182
return fmt .Errorf ("failed to get git integration: %w" , err )
@@ -184,26 +192,19 @@ func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
184
192
accountAdminsOnly bool
185
193
)
186
194
187
- providers := map [string ]model.GitProviders {
188
- "github" : model .GitProvidersGithub ,
189
- "gitlab" : model .GitProvidersGitlab ,
190
- }
191
-
192
195
cmd := & cobra.Command {
193
- Use : "add NAME" ,
196
+ Use : "add [ NAME] " ,
194
197
Short : "Add a new git integration" ,
195
198
RunE : func (cmd * cobra.Command , args []string ) error {
196
- if len (args ) < 1 {
197
- return fmt .Errorf ("missing integration name" )
198
- }
199
+ var err error
199
200
200
- opts .Name = args [0 ]
201
+ if len (args ) > 0 {
202
+ opts .Name = & args [0 ]
203
+ }
201
204
202
- p , ok := providers [provider ]
203
- if ! ok {
204
- return fmt .Errorf ("provider '%s' is not a valid provider name" , provider )
205
+ if opts .Provider , err = parseGitProvider (provider ); err != nil {
206
+ return err
205
207
}
206
- opts .Provider = p
207
208
208
209
opts .SharingPolicy = model .SharingPolicyAllUsersInAccount
209
210
if accountAdminsOnly {
@@ -242,15 +243,13 @@ func NewGitIntegrationEditCommand(client *sdk.AppProxyAPI) *cobra.Command {
242
243
)
243
244
244
245
cmd := & cobra.Command {
245
- Use : "edit NAME" ,
246
+ Use : "edit [ NAME] " ,
246
247
Short : "Edit a git integration" ,
247
248
RunE : func (cmd * cobra.Command , args []string ) error {
248
- if len (args ) < 1 {
249
- return fmt . Errorf ( "missing integration name" )
249
+ if len (args ) > 0 {
250
+ opts . Name = & args [ 0 ]
250
251
}
251
252
252
- opts .Name = args [0 ]
253
-
254
253
opts .SharingPolicy = model .SharingPolicyAllUsersInAccount
255
254
if accountAdminsOnly {
256
255
opts .SharingPolicy = model .SharingPolicyAccountAdmins
@@ -310,15 +309,13 @@ func NewGitIntegrationRegisterCommand(client *sdk.AppProxyAPI) *cobra.Command {
310
309
)
311
310
312
311
cmd := & cobra.Command {
313
- Use : "register NAME" ,
312
+ Use : "register [ NAME] " ,
314
313
Short : "Register to a git integrations" ,
315
314
RunE : func (cmd * cobra.Command , args []string ) error {
316
- if len (args ) < 1 {
317
- return fmt . Errorf ( "missing integration name" )
315
+ if len (args ) > 0 {
316
+ opts . Name = & args [ 0 ]
318
317
}
319
318
320
- opts .Name = args [0 ]
321
-
322
319
return RunGitIntegrationRegisterCommand (cmd .Context (), * client , & opts )
323
320
},
324
321
}
@@ -344,22 +341,26 @@ func RunGitIntegrationRegisterCommand(ctx context.Context, client sdk.AppProxyAP
344
341
}
345
342
346
343
func NewGitIntegrationDeregisterCommand (client * sdk.AppProxyAPI ) * cobra.Command {
344
+ var (
345
+ integration * string
346
+ )
347
+
347
348
cmd := & cobra.Command {
348
- Use : "deregister NAME" ,
349
+ Use : "deregister [ NAME] " ,
349
350
Short : "Deregister user from a git integrations" ,
350
351
RunE : func (cmd * cobra.Command , args []string ) error {
351
- if len (args ) < 1 {
352
- return fmt . Errorf ( "missing integration name" )
352
+ if len (args ) > 0 {
353
+ integration = & args [ 0 ]
353
354
}
354
355
355
- return RunGitIntegrationDeregisterCommand (cmd .Context (), * client , args [ 0 ] )
356
+ return RunGitIntegrationDeregisterCommand (cmd .Context (), * client , integration )
356
357
},
357
358
}
358
359
359
360
return cmd
360
361
}
361
362
362
- func RunGitIntegrationDeregisterCommand (ctx context.Context , client sdk.AppProxyAPI , name string ) error {
363
+ func RunGitIntegrationDeregisterCommand (ctx context.Context , client sdk.AppProxyAPI , name * string ) error {
363
364
gi , err := client .GitIntegrations ().Deregister (ctx , name )
364
365
if err != nil {
365
366
return fmt .Errorf ("failed to deregister user from git integration: %w" , err )
@@ -430,3 +431,11 @@ func verifyOutputFormat(format string, allowedFormats ...string) error {
430
431
431
432
return fmt .Errorf ("invalid output format: %s" , format )
432
433
}
434
+
435
+ func parseGitProvider (provider string ) (model.GitProviders , error ) {
436
+ p , ok := gitProvidersByName [provider ]
437
+ if ! ok {
438
+ return model .GitProviders ("" ), fmt .Errorf ("provider '%s' is not a valid provider name" , provider )
439
+ }
440
+ return p , nil
441
+ }
0 commit comments