@@ -192,9 +192,14 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i
192192 runCmds .InitEnterpriseInstallerRM (enterpriseInstallerCmd )
193193 runCmds .InitEnterpriseInstallerAssign (enterpriseInstallerCmd )
194194
195+ appCmd := runCmds .InitAppCommand (runCmds .rootCmd )
196+ runCmds .InitAppList (appCmd )
197+ runCmds .InitAppCreate (appCmd )
198+ runCmds .InitAppDelete (appCmd )
199+
195200 runCmds .rootCmd .SetUsageTemplate (rootCmdUsageTmpl )
196201
197- prerunCommand := func (cmd * cobra.Command , args []string ) error {
202+ preRunSetupAPIs := func (_ * cobra.Command , _ []string ) error {
198203 if apiToken == "" {
199204 apiToken = os .Getenv ("REPLICATED_API_TOKEN" )
200205 if apiToken == "" {
@@ -218,33 +223,40 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i
218223
219224 commonAPI := client .NewClient (platformOrigin , graphqlOrigin , apiToken , kurlDotSHOrigin )
220225 runCmds .api = commonAPI
226+ return nil
227+ }
228+
229+ prerunCommand := func (cmd * cobra.Command , args []string ) error {
230+ if err := preRunSetupAPIs (cmd , args ); err != nil {
231+ return errors .Wrap (err , "set up APIs" )
232+ }
221233
222234 if appSlugOrID == "" {
223235 appSlugOrID = os .Getenv ("REPLICATED_APP" )
224236 }
225237
226- appType , err := commonAPI .GetAppType (appSlugOrID )
238+ appType , err := runCmds . api .GetAppType (appSlugOrID )
227239 if err != nil {
228240 return err
229241 }
230242 runCmds .appType = appType
231243
232244 if appType == "platform" {
233- app , err := platformAPI .GetApp (appSlugOrID )
245+ app , err := runCmds . platformAPI .GetApp (appSlugOrID )
234246 if err != nil {
235247 return err
236248 }
237249 runCmds .appID = app .Id
238250 runCmds .appSlug = app .Slug
239251 } else if appType == "ship" {
240- app , err := shipAPI .GetApp (appSlugOrID )
252+ app , err := runCmds . shipAPI .GetApp (appSlugOrID )
241253 if err != nil {
242254 return err
243255 }
244256 runCmds .appID = app .ID
245257 runCmds .appSlug = app .Slug
246258 } else if appType == "kots" {
247- app , err := kotsAPI .GetApp (appSlugOrID )
259+ app , err := runCmds . kotsAPI .GetApp (appSlugOrID )
248260 if err != nil {
249261 return err
250262 }
@@ -255,12 +267,14 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i
255267 return nil
256268 }
257269
270+
258271 channelCmd .PersistentPreRunE = prerunCommand
259272 releaseCmd .PersistentPreRunE = prerunCommand
260273 collectorsCmd .PersistentPreRunE = prerunCommand
261274 entitlementsCmd .PersistentPreRunE = prerunCommand
262275 customersCmd .PersistentPreRunE = prerunCommand
263276 installerCmd .PersistentPreRunE = prerunCommand
277+ appCmd .PersistentPreRunE = preRunSetupAPIs
264278
265279 runCmds .rootCmd .AddCommand (Version ())
266280
0 commit comments