@@ -39,6 +39,11 @@ type (
3939 }
4040)
4141
42+ var gitProvidersByName = map [string ]model.GitProviders {
43+ "github" : model .GitProvidersGithub ,
44+ "gitlab" : model .GitProvidersGitlab ,
45+ }
46+
4247func NewIntegrationCommand () * cobra.Command {
4348 var (
4449 runtime string
@@ -60,6 +65,8 @@ func NewIntegrationCommand() *cobra.Command {
6065
6166 cmd .AddCommand (NewGitIntegrationCommand (& client ))
6267
68+ cmd .Hidden = true // hide this command for now
69+
6370 return cmd
6471}
6572
@@ -142,24 +149,25 @@ func RunGitIntegrationListCommand(ctx context.Context, client sdk.AppProxyAPI, f
142149
143150func NewGitIntegrationGetCommand (client * sdk.AppProxyAPI ) * cobra.Command {
144151 var (
145- format string
152+ format string
153+ integration * string
146154 )
147155
148156 allowedFormats := []string {"yaml" , "yml" , "json" }
149157
150158 cmd := & cobra.Command {
151- Use : "get NAME" ,
159+ Use : "get [ NAME] " ,
152160 Short : "Retrieve a git integration" ,
153161 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 ]
156164 }
157165
158166 if err := verifyOutputFormat (format , allowedFormats ... ); err != nil {
159167 return err
160168 }
161169
162- return RunGitIntegrationGetCommand (cmd .Context (), * client , args [ 0 ] , format )
170+ return RunGitIntegrationGetCommand (cmd .Context (), * client , integration , format )
163171 },
164172 }
165173
@@ -168,7 +176,7 @@ func NewGitIntegrationGetCommand(client *sdk.AppProxyAPI) *cobra.Command {
168176 return cmd
169177}
170178
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 {
172180 gi , err := client .GitIntegrations ().Get (ctx , name )
173181 if err != nil {
174182 return fmt .Errorf ("failed to get git integration: %w" , err )
@@ -184,26 +192,19 @@ func NewGitIntegrationAddCommand(client *sdk.AppProxyAPI) *cobra.Command {
184192 accountAdminsOnly bool
185193 )
186194
187- providers := map [string ]model.GitProviders {
188- "github" : model .GitProvidersGithub ,
189- "gitlab" : model .GitProvidersGitlab ,
190- }
191-
192195 cmd := & cobra.Command {
193- Use : "add NAME" ,
196+ Use : "add [ NAME] " ,
194197 Short : "Add a new git integration" ,
195198 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
199200
200- opts .Name = args [0 ]
201+ if len (args ) > 0 {
202+ opts .Name = & args [0 ]
203+ }
201204
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
205207 }
206- opts .Provider = p
207208
208209 opts .SharingPolicy = model .SharingPolicyAllUsersInAccount
209210 if accountAdminsOnly {
@@ -242,15 +243,13 @@ func NewGitIntegrationEditCommand(client *sdk.AppProxyAPI) *cobra.Command {
242243 )
243244
244245 cmd := & cobra.Command {
245- Use : "edit NAME" ,
246+ Use : "edit [ NAME] " ,
246247 Short : "Edit a git integration" ,
247248 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 ]
250251 }
251252
252- opts .Name = args [0 ]
253-
254253 opts .SharingPolicy = model .SharingPolicyAllUsersInAccount
255254 if accountAdminsOnly {
256255 opts .SharingPolicy = model .SharingPolicyAccountAdmins
@@ -310,15 +309,13 @@ func NewGitIntegrationRegisterCommand(client *sdk.AppProxyAPI) *cobra.Command {
310309 )
311310
312311 cmd := & cobra.Command {
313- Use : "register NAME" ,
312+ Use : "register [ NAME] " ,
314313 Short : "Register to a git integrations" ,
315314 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 ]
318317 }
319318
320- opts .Name = args [0 ]
321-
322319 return RunGitIntegrationRegisterCommand (cmd .Context (), * client , & opts )
323320 },
324321 }
@@ -344,22 +341,26 @@ func RunGitIntegrationRegisterCommand(ctx context.Context, client sdk.AppProxyAP
344341}
345342
346343func NewGitIntegrationDeregisterCommand (client * sdk.AppProxyAPI ) * cobra.Command {
344+ var (
345+ integration * string
346+ )
347+
347348 cmd := & cobra.Command {
348- Use : "deregister NAME" ,
349+ Use : "deregister [ NAME] " ,
349350 Short : "Deregister user from a git integrations" ,
350351 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 ]
353354 }
354355
355- return RunGitIntegrationDeregisterCommand (cmd .Context (), * client , args [ 0 ] )
356+ return RunGitIntegrationDeregisterCommand (cmd .Context (), * client , integration )
356357 },
357358 }
358359
359360 return cmd
360361}
361362
362- func RunGitIntegrationDeregisterCommand (ctx context.Context , client sdk.AppProxyAPI , name string ) error {
363+ func RunGitIntegrationDeregisterCommand (ctx context.Context , client sdk.AppProxyAPI , name * string ) error {
363364 gi , err := client .GitIntegrations ().Deregister (ctx , name )
364365 if err != nil {
365366 return fmt .Errorf ("failed to deregister user from git integration: %w" , err )
@@ -430,3 +431,11 @@ func verifyOutputFormat(format string, allowedFormats ...string) error {
430431
431432 return fmt .Errorf ("invalid output format: %s" , format )
432433}
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