organization/orgs.go
func (m *DefaultManager) DeleteOrgs() error {
	m.orgs = nil
	orgsConfig, err := m.Cfg.Orgs()
	if err != nil {
		return err
	}

	if !orgsConfig.EnableDeleteOrgs {
		lo.G.Debug("Org deletion is not enabled.  Set enable-delete-orgs: true")
		return nil
	}

	configuredOrgs := make(map[string]bool)
	for _, orgName := range orgsConfig.Orgs {
		configuredOrgs[orgName] = true
	}

	orgs, err := m.ListOrgs()
	if err != nil {
		return err
	}

	orgsToDelete := make([]cfclient.Org, 0)
	for _, org := range orgs {
		if _, exists := configuredOrgs[org.Name]; !exists {
			if !Matches(org.Name, orgsConfig.ProtectedOrgList()) {
				orgsToDelete = append(orgsToDelete, org)
			} else {
				lo.G.Infof("Protected org [%s] - will not be deleted", org.Name)
			}
		}
	}

	for _, org := range orgsToDelete {
		if err := m.DeleteOrg(org); err != nil {
			return err
		}
	}
	m.orgs = nil
	return nil
}
func (m *DefaultManager) DeleteOrgs() error {
	m.orgs = nil
	orgsConfig, err := m.Cfg.Orgs()
	if err != nil {
		return err
	}

	if !orgsConfig.EnableDeleteOrgs {
		lo.G.Debug("Org deletion is not enabled.  Set enable-delete-orgs: true")
		return nil
	}

	configuredOrgs := make(map[string]bool)
	for _, orgName := range orgsConfig.Orgs {
		configuredOrgs[orgName] = true
	}

	orgs, err := m.ListOrgs()
	if err != nil {
		return err
	}

	orgsToDelete := make([]cfclient.Org, 0)
	for _, org := range orgs {
		if _, exists := configuredOrgs[org.Name]; !exists {
			if !Matches(org.Name, orgsConfig.ProtectedOrgList()) {
				orgsToDelete = append(orgsToDelete, org)
			} else {
				lo.G.Infof("Protected org [%s] - will not be deleted", org.Name)
			}
		}
	}

	for _, org := range orgsToDelete {
		if err := m.DeleteOrg(org); err != nil {
			return err
		}
	}
	m.orgs = nil
	return nil
}
func ( m * DefaultManager ) DeleteOrgs ( ) error { m . orgs = nil orgsConfig , err := m . Cfg . Orgs ( ) if err != nil { return err } if ! orgsConfig . EnableDeleteOrgs { lo . G . Debug ( " " ) return nil } configuredOrgs := make ( map [ string ] bool ) for _ , orgName := range orgsConfig . Orgs { configuredOrgs [ orgName ] = true } orgs , err := m . ListOrgs ( ) if err != nil { return err } orgsToDelete := make ( [ ] cfclient . Org , 0 ) for _ , org := range orgs { if _ , exists := configuredOrgs [ org . Name ] ; ! exists { if ! Matches ( org . Name , orgsConfig . ProtectedOrgList ( ) ) { orgsToDelete = append ( orgsToDelete , org ) } else { lo . G . Infof ( " " , org . Name ) } } } for _ , org := range orgsToDelete { if err := m . DeleteOrg ( org ) ; err != nil { return err } } m . orgs = nil return nil }
//DeleteOrgs -
DeleteOrgs -