github.com/arunkumar7540/cli@v6.45.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  	}
    51  
    52  	if settings.DiskQuota != 0 {
    53  		app.DiskQuota.ParseUint64Value(&settings.DiskQuota)
    54  	}
    55  
    56  	if settings.DockerImage != "" {
    57  		app.DockerImage = settings.DockerImage
    58  	}
    59  
    60  	if settings.DockerUsername != "" {
    61  		app.DockerUsername = settings.DockerUsername
    62  	}
    63  
    64  	if settings.DockerPassword != "" {
    65  		app.DockerPassword = settings.DockerPassword
    66  	}
    67  
    68  	if settings.DropletPath != "" {
    69  		app.DropletPath = settings.DropletPath
    70  	}
    71  
    72  	if settings.HealthCheckTimeout != 0 {
    73  		app.HealthCheckTimeout = settings.HealthCheckTimeout
    74  	}
    75  
    76  	if settings.HealthCheckType != "" {
    77  		app.HealthCheckType = settings.HealthCheckType
    78  	}
    79  
    80  	if settings.Instances.IsSet {
    81  		app.Instances = settings.Instances
    82  	}
    83  
    84  	if settings.Memory != 0 {
    85  		app.Memory.ParseUint64Value(&settings.Memory)
    86  	}
    87  
    88  	if settings.Name != "" {
    89  		app.Name = settings.Name
    90  	}
    91  
    92  	if settings.NoHostname {
    93  		app.NoHostname = true
    94  	}
    95  
    96  	if settings.NoRoute {
    97  		app.NoRoute = true
    98  	}
    99  
   100  	if settings.ProvidedAppPath != "" {
   101  		app.Path = settings.ProvidedAppPath
   102  	}
   103  
   104  	if app.Path == "" && app.DockerImage == "" && app.DropletPath == "" {
   105  		app.Path = settings.CurrentDirectory
   106  	}
   107  
   108  	if settings.RandomRoute {
   109  		app.RandomRoute = true
   110  	}
   111  
   112  	if settings.RoutePath != "" {
   113  		app.RoutePath = settings.RoutePath
   114  	}
   115  
   116  	if settings.StackName != "" {
   117  		app.StackName = settings.StackName
   118  	}
   119  
   120  	return app
   121  }
   122  
   123  func (settings CommandLineSettings) setBuildpacks(app manifest.Application) manifest.Application {
   124  	app.Buildpack = types.FilteredString{}
   125  	app.Buildpacks = nil
   126  
   127  	if len(settings.Buildpacks) == 1 {
   128  		app.Buildpack.ParseValue(settings.Buildpacks[0])
   129  		return app
   130  	}
   131  
   132  	for _, bp := range settings.Buildpacks {
   133  		app.Buildpacks = append(app.Buildpacks, bp)
   134  	}
   135  
   136  	return app
   137  }
   138  
   139  func (settings CommandLineSettings) String() string {
   140  	return fmt.Sprintf(
   141  		"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'",
   142  		settings.Name,
   143  		strings.Join(settings.Buildpacks, ", "),
   144  		settings.Command.IsSet,
   145  		settings.Command.Value,
   146  		settings.CurrentDirectory,
   147  		settings.DiskQuota,
   148  		settings.DockerImage,
   149  		settings.DropletPath,
   150  		settings.HealthCheckTimeout,
   151  		settings.HealthCheckType,
   152  		settings.Instances.IsSet,
   153  		settings.Instances.Value,
   154  		settings.Memory,
   155  		settings.ProvidedAppPath,
   156  		settings.StackName,
   157  		settings.RoutePath,
   158  		settings.DefaultRouteDomain,
   159  		settings.DefaultRouteHostname,
   160  	)
   161  }