github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7pushaction/handle_app_name_override.go (about)

     1  package v7pushaction
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/errors"
     5  	"code.cloudfoundry.org/cli/command/translatableerror"
     6  	"code.cloudfoundry.org/cli/util/manifestparser"
     7  )
     8  
     9  func HandleAppNameOverride(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
    10  	if manifest.ContainsMultipleApps() && manifest.HasAppWithNoName() {
    11  		return manifest, errors.New("Found an application with no name specified.")
    12  	}
    13  
    14  	if overrides.AppName != "" {
    15  		newApps := make([]manifestparser.Application, 1)
    16  
    17  		foundApp := false
    18  		for _, app := range manifest.Applications {
    19  			if app.Name == overrides.AppName {
    20  				newApps[0] = app
    21  				foundApp = true
    22  				break
    23  			}
    24  		}
    25  
    26  		if !foundApp {
    27  			if len(manifest.Applications) == 1 {
    28  				manifest.Applications[0].Name = overrides.AppName
    29  				return manifest, nil
    30  			}
    31  
    32  			return manifest, manifestparser.AppNotInManifestError{Name: overrides.AppName}
    33  		}
    34  
    35  		manifest.Applications = newApps
    36  	} else if manifest.HasAppWithNoName() {
    37  		return manifest, translatableerror.AppNameOrManifestRequiredError{}
    38  	}
    39  
    40  	return manifest, nil
    41  }