|
|
@@ -22,10 +22,7 @@ func SetProfile(currentProfile string) error {
|
|
|
|
|
|
// SetDriver sets the driver used when building images. This can either be locla or github
|
|
|
func SetDriver(driver string, currentProfile string) error {
|
|
|
- v := CLIConfig{
|
|
|
- Driver: driver,
|
|
|
- }
|
|
|
- return updateValuesForSelectedProfile(currentProfile, v, porterConfigFilePath)
|
|
|
+ return updateValuesForSelectedProfile(currentProfile, porterConfigFilePath, withDriver(driver))
|
|
|
}
|
|
|
|
|
|
// SetHost updates the host for the current profile. This clears the project, cluster, and token as they will not work with the new host
|
|
|
@@ -33,60 +30,40 @@ func SetDriver(driver string, currentProfile string) error {
|
|
|
func SetHost(host string, currentProfile string) error {
|
|
|
host = strings.TrimRight(host, "/")
|
|
|
|
|
|
- v := defaultCLIConfig()
|
|
|
- v.Host = host
|
|
|
-
|
|
|
color.New(color.FgGreen).Printf("Set the current host as %s\n", host) //nolint:errcheck,gosec
|
|
|
|
|
|
- return updateValuesForSelectedProfile(currentProfile, v, porterConfigFilePath)
|
|
|
+ return updateValuesForSelectedProfile(currentProfile, porterConfigFilePath, withHost(host), withClusterID(0), withProjectID(0))
|
|
|
}
|
|
|
|
|
|
// SetProject sets a project for all API commands
|
|
|
func SetProject(projectID uint, currentProfile string) error {
|
|
|
color.New(color.FgGreen).Printf("Set the current project as %d\n", projectID) //nolint:errcheck,gosec
|
|
|
|
|
|
- v := CLIConfig{
|
|
|
- Project: projectID,
|
|
|
- }
|
|
|
-
|
|
|
- return updateValuesForSelectedProfile(currentProfile, v, porterConfigFilePath)
|
|
|
+ return updateValuesForSelectedProfile(currentProfile, porterConfigFilePath, withProjectID(0))
|
|
|
}
|
|
|
|
|
|
// SetCluster sets the cluster in the current profile. All further actions will be targeted at this cluster
|
|
|
func SetCluster(clusterID uint, currentProfile string) error {
|
|
|
color.New(color.FgGreen).Printf("Set the current cluster as %d\n", clusterID) //nolint:errcheck,gosec
|
|
|
-
|
|
|
- v := CLIConfig{
|
|
|
- Cluster: clusterID,
|
|
|
- Kubeconfig: "",
|
|
|
- }
|
|
|
- return updateValuesForSelectedProfile(currentProfile, v, porterConfigFilePath)
|
|
|
+ return updateValuesForSelectedProfile(currentProfile, porterConfigFilePath, withClusterID(0), withKubeconfig(""))
|
|
|
}
|
|
|
|
|
|
// SetToken sets the token in the current profile. All further actions will be authenticated with this token
|
|
|
func SetToken(token string, currentProfile string) error {
|
|
|
- v := CLIConfig{
|
|
|
- Token: token,
|
|
|
- }
|
|
|
- return updateValuesForSelectedProfile(currentProfile, v, porterConfigFilePath)
|
|
|
+ return updateValuesForSelectedProfile(currentProfile, porterConfigFilePath, withToken(token))
|
|
|
}
|
|
|
|
|
|
// SetRegistry sets the docker registry in the current profile. All further actions will be targeted at this registry
|
|
|
func SetRegistry(registryID uint) error {
|
|
|
color.New(color.FgGreen).Printf("Set the current registry as %d\n", registryID) //nolint:errcheck,gosec
|
|
|
- v := CLIConfig{
|
|
|
- Registry: registryID,
|
|
|
- }
|
|
|
- return updateValuesForSelectedProfile(currentProfile, v, porterConfigFilePath)
|
|
|
+ return updateValuesForSelectedProfile(currentProfile, porterConfigFilePath, withRegistryID(registryID))
|
|
|
}
|
|
|
|
|
|
// SetHelmRepo sets the helm repo in the current profile. All further actions will be targeted at this helm repo
|
|
|
func SetHelmRepo(helmRepoID uint) error {
|
|
|
color.New(color.FgGreen).Printf("Set the current Helm repo as %d\n", helmRepoID) //nolint:errcheck,gosec
|
|
|
- v := CLIConfig{
|
|
|
- HelmRepo: helmRepoID,
|
|
|
- }
|
|
|
- return updateValuesForSelectedProfile(currentProfile, v, porterConfigFilePath)
|
|
|
+
|
|
|
+ return updateValuesForSelectedProfile(currentProfile, porterConfigFilePath, withHelmRepoID(helmRepoID))
|
|
|
}
|
|
|
|
|
|
// SetKubeconfig sets the kubeconfig in the current profile. All further actions which require kubernetes will be targeted at this kubeconfig
|
|
|
@@ -102,8 +79,63 @@ func SetKubeconfig(kubeconfig string) error {
|
|
|
|
|
|
color.New(color.FgGreen).Printf("Set the path to kubeconfig as %s\n", path) //nolint:errcheck,gosec
|
|
|
|
|
|
- v := CLIConfig{
|
|
|
- Kubeconfig: kubeconfig,
|
|
|
+ return updateValuesForSelectedProfile(currentProfile, porterConfigFilePath, withKubeconfig(kubeconfig))
|
|
|
+}
|
|
|
+
|
|
|
+// cliConfigValue allows for overridden CLI config values allowing for default values, without requiring nil.
|
|
|
+type cliConfigValue func(*CLIConfig)
|
|
|
+
|
|
|
+func withClusterID(clusterID uint) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c.Cluster = clusterID
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func withToken(token string) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c.Token = token
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func withRegistryID(registryID uint) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c.Registry = registryID
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func withHelmRepoID(helmRepoID uint) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c.HelmRepo = helmRepoID
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func withKubeconfig(kubeconfig string) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c.Kubeconfig = kubeconfig
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func withHost(host string) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c.Host = host
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func withProjectID(projectID uint) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c.Project = projectID
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func withDriver(driver string) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c.Driver = driver
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// withCLIConfig will completely override the CLI config with the provided one
|
|
|
+func withCLIConfig(newConfig CLIConfig) cliConfigValue {
|
|
|
+ return func(c *CLIConfig) {
|
|
|
+ c = &newConfig
|
|
|
}
|
|
|
- return updateValuesForSelectedProfile(currentProfile, v, porterConfigFilePath)
|
|
|
}
|