fix: only use flag value as default or if altered (#1223)

This commit is contained in:
Luke Kingland 2022-09-07 14:47:18 -06:00 committed by GitHub
parent 2ee2c61b8b
commit 4e5e9927b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View File

@ -87,6 +87,13 @@ func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err erro
// Load the Function at path, and if it is initialized, update it with
// pertinent values from the config.
//
// NOTE: the checks for .Changed and altered conditionals for defaults will
// be removed when Global Config is integreated, because the config object
// will at that time contain the final value for the attribute, taking into
// account whether or not the value was altered via flags or env variables.
// This condition is also only necessary for config members whose default
// value deviates from the zero value.
f, err := fn.NewFunction(config.Path)
if err != nil {
return
@ -94,15 +101,17 @@ func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err erro
if !f.Initialized() {
return fmt.Errorf("'%v' does not contain an initialized function", config.Path)
}
if config.Registry != "" {
if f.Registry == "" || cmd.Flags().Changed("registry") {
// Sets default AND accepts any user-provided overrides
f.Registry = config.Registry
}
if f.Builder == "" || cmd.Flags().Changed("builder") {
// Sets default AND accepts any user-provided overrides
f.Builder = config.Builder
}
if config.Image != "" {
f.Image = config.Image
}
if config.Builder != "" {
f.Builder = config.Builder
}
// Choose a builder based on the value of the --builder flag
var builder fn.Builder

View File

@ -128,15 +128,17 @@ func runDeploy(cmd *cobra.Command, _ []string, newClient ClientFactory) (err err
if !f.Initialized() {
return fmt.Errorf("'%v' does not contain an initialized function", config.Path)
}
if config.Registry != "" {
if f.Registry == "" || cmd.Flags().Changed("registry") {
// Sets default AND accepts any user-provided overrides
f.Registry = config.Registry
}
if f.Builder == "" || cmd.Flags().Changed("builder") {
// Sets default AND accepts any user-provided overrides
f.Builder = config.Builder
}
if config.Image != "" {
f.Image = config.Image
}
if config.Builder != "" {
f.Builder = config.Builder
}
f.Namespace, err = checkNamespaceDeploy(f.Namespace, config.Namespace)
if err != nil {