From 4e5e9927b24576ba7ca5fbe6d08c0eefa65bc266 Mon Sep 17 00:00:00 2001 From: Luke Kingland <58986931+lkingland@users.noreply.github.com> Date: Wed, 7 Sep 2022 14:47:18 -0600 Subject: [PATCH] fix: only use flag value as default or if altered (#1223) --- cmd/build.go | 17 +++++++++++++---- cmd/deploy.go | 10 ++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/cmd/build.go b/cmd/build.go index 25d13c932..7a545ead0 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -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 diff --git a/cmd/deploy.go b/cmd/deploy.go index 44bc14d62..24bcea2f6 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -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 {