11import { BaseCommand } from "./base-command" ;
22import { flags } from "@contentstack/cli-utilities" ;
3- import { getOrg , getApp , fetchApp , getInstallation , uninstallApp } from "../../util" ;
3+ import { getOrg , getApp , fetchApp } from "../../util" ;
44import { commonMsg , uninstallAppMsg } from "../../messages" ;
5+ import { UninstallAppFactory } from "../../factories/uninstall-app-factory" ;
56
67export default class Uninstall extends BaseCommand < typeof Uninstall > {
78 static description = "Uninstall an app" ;
@@ -19,6 +20,9 @@ export default class Uninstall extends BaseCommand<typeof Uninstall> {
1920 } ) ,
2021 'installation-uid' : flags . string ( {
2122 description : uninstallAppMsg . INSTALLATION_UID
23+ } ) ,
24+ 'uninstall-all' : flags . boolean ( {
25+ description : uninstallAppMsg . UNINSTALL_ALL ,
2226 } )
2327 }
2428
@@ -34,17 +38,14 @@ export default class Uninstall extends BaseCommand<typeof Uninstall> {
3438 } else {
3539 app = await fetchApp ( this . flags , this . sharedConfig . org , { managementSdk : this . managementAppSdk , log : this . log } )
3640 }
37-
41+
3842 this . flags [ 'app-uid' ] = app ?. uid ;
3943 appType = app ?. [ 'target_type' ]
4044
41- // select installation uid to uninstall
42- if ( ! this . flags [ 'installation-uid' ] ) {
43- this . flags [ 'installation-uid' ] = await getInstallation ( this . flags , this . sharedConfig . org , this . managementSdk , appType , { managementSdk : this . managementAppSdk , log : this . log } )
44- }
45-
46- // uninstall app
47- await uninstallApp ( this . flags , this . sharedConfig . org , { managementSdk : this . managementAppSdk , log : this . log } )
45+ const factory = new UninstallAppFactory ( )
46+ const strategy = factory . getStrategyInstance ( this . flags [ 'uninstall-all' ] )
47+ await strategy . run ( this . flags , this . sharedConfig . org , this . managementSdk , { managementSdk : this . managementAppSdk , log : this . log } , appType )
48+
4849 this . log ( this . $t ( uninstallAppMsg . APP_UNINSTALLED , { app : app ?. name || this . flags [ "app-uid" ] } ) , "info" )
4950
5051 } catch ( error : any ) {
0 commit comments