[feat] Tweaked cli options reader. Ignore option which has no cobra flag.
@@ -16,10 +16,10 @@ func NewCLIOptionsReader(cmd *cobra.Command) CLIOptionsReader {
return CLIOptionsReader{cmd: cmd}
}
-// Read queries the cobra command for a cli options associated with
-// the given InstallationOption and returns its value converted to the
+// Queries the cobra command for a flag associated with the given
+// InstallationOption and returns its value converted to the
// appropriate (Go) type as defined by the Type field of the
-// InstallationOption.
+// InstallationOption. Does nothing if no cobra flag is found.
func (reader CLIOptionsReader) Read(option *InstallationOption) error {
// Translate option name
flagName := strings.ReplaceAll(option.Name, "_", "-")
@@ -33,6 +33,13 @@ func (reader CLIOptionsReader) Read(option *InstallationOption) error {
// documentation has not shown me a way to properly determine
// if a flag was not used on the command line at all,
// vs. specified with (possibly the default) value.
+ //
+ // Do nothing if the specified option has no associated cobra
+ // flag.
+
+ if reader.cmd.Flags().Lookup(flagName) == nil {
+ return nil
+ }
var cliValue interface{}
var cliValid bool
