github.com/sleungcy/cli@v7.1.0+incompatible/actor/pushaction/command_line_settings.go (about) 1 package pushaction 2 3 import ( 4 "fmt" 5 "strings" 6 7 "code.cloudfoundry.org/cli/types" 8 "code.cloudfoundry.org/cli/util/manifest" 9 ) 10 11 type CommandLineSettings struct { 12 Buildpacks []string 13 Command types.FilteredString 14 CurrentDirectory string 15 DefaultRouteDomain string 16 DefaultRouteHostname string 17 DiskQuota uint64 18 DockerImage string 19 DockerPassword string 20 DockerUsername string 21 DropletPath string 22 HealthCheckTimeout uint64 23 HealthCheckType string 24 Instances types.NullInt 25 Memory uint64 26 Name string 27 NoHostname bool 28 NoRoute bool 29 ProvidedAppPath string 30 RandomRoute bool 31 RoutePath string 32 StackName string 33 } 34 35 func (settings CommandLineSettings) OverrideManifestSettings(app manifest.Application) manifest.Application { 36 if len(settings.Buildpacks) > 0 { 37 app = settings.setBuildpacks(app) 38 } 39 40 if settings.Command.IsSet { 41 app.Command = settings.Command 42 } 43 44 if settings.DefaultRouteDomain != "" { 45 app.Domain = settings.DefaultRouteDomain 46 } 47 48 if settings.DefaultRouteHostname != "" { 49 app.Hostname = settings.DefaultRouteHostname 50 app.RandomRoute = false 51 } 52 53 if settings.DiskQuota != 0 { 54 app.DiskQuota.ParseUint64Value(&settings.DiskQuota) 55 } 56 57 if settings.DockerImage != "" { 58 app.DockerImage = settings.DockerImage 59 } 60 61 if settings.DockerUsername != "" { 62 app.DockerUsername = settings.DockerUsername 63 } 64 65 if settings.DockerPassword != "" { 66 app.DockerPassword = settings.DockerPassword 67 } 68 69 if settings.DropletPath != "" { 70 app.DropletPath = settings.DropletPath 71 } 72 73 if settings.HealthCheckTimeout != 0 { 74 app.HealthCheckTimeout = settings.HealthCheckTimeout 75 } 76 77 if settings.HealthCheckType != "" { 78 app.HealthCheckType = settings.HealthCheckType 79 } 80 81 if settings.Instances.IsSet { 82 app.Instances = settings.Instances 83 } 84 85 if settings.Memory != 0 { 86 app.Memory.ParseUint64Value(&settings.Memory) 87 } 88 89 if settings.Name != "" { 90 app.Name = settings.Name 91 } 92 93 if settings.NoHostname { 94 app.NoHostname = true 95 } 96 97 if settings.NoRoute { 98 app.NoRoute = true 99 } 100 101 if settings.ProvidedAppPath != "" { 102 app.Path = settings.ProvidedAppPath 103 } 104 105 if app.Path == "" && app.DockerImage == "" && app.DropletPath == "" { 106 app.Path = settings.CurrentDirectory 107 } 108 109 if settings.RandomRoute { 110 app.RandomRoute = true 111 } 112 113 if settings.RoutePath != "" { 114 app.RoutePath = settings.RoutePath 115 } 116 117 if settings.StackName != "" { 118 app.StackName = settings.StackName 119 } 120 121 return app 122 } 123 124 func (settings CommandLineSettings) setBuildpacks(app manifest.Application) manifest.Application { 125 app.Buildpack = types.FilteredString{} 126 app.Buildpacks = nil 127 128 if len(settings.Buildpacks) == 1 { 129 app.Buildpack.ParseValue(settings.Buildpacks[0]) 130 return app 131 } 132 133 for _, bp := range settings.Buildpacks { 134 app.Buildpacks = append(app.Buildpacks, bp) 135 } 136 137 return app 138 } 139 140 func (settings CommandLineSettings) String() string { 141 return fmt.Sprintf( 142 "App Name: '%s', Buildpacks: %s, Command: (%t, '%s'), CurrentDirectory: '%s', Disk Quota: '%d', Docker Image: '%s', Droplet: '%s', Health Check Timeout: '%d', Health Check Type: '%s', Instances: (%t, '%d'), Memory: '%d', Provided App Path: '%s', Stack: '%s', RoutePath: '%s', Domain: '%s', Hostname: '%s'", 143 settings.Name, 144 strings.Join(settings.Buildpacks, ", "), 145 settings.Command.IsSet, 146 settings.Command.Value, 147 settings.CurrentDirectory, 148 settings.DiskQuota, 149 settings.DockerImage, 150 settings.DropletPath, 151 settings.HealthCheckTimeout, 152 settings.HealthCheckType, 153 settings.Instances.IsSet, 154 settings.Instances.Value, 155 settings.Memory, 156 settings.ProvidedAppPath, 157 settings.StackName, 158 settings.RoutePath, 159 settings.DefaultRouteDomain, 160 settings.DefaultRouteHostname, 161 ) 162 }