func viperizeFlags(requiredConfig, optionalConfig string, flags *flag.FlagSet) error {
	viperConfig := optionalConfig
	required := false
	if requiredConfig != "" {
		viperConfig = requiredConfig
		required = true
	}
	if viperConfig == "" {
		return nil
	}
	viper.SetConfigName(filepath.Base(viperConfig))
	viper.AddConfigPath(filepath.Dir(viperConfig))
	wrapError := func(err error) error {
		if err == nil {
			return nil
		}
		errorPrefix := fmt.Sprintf("viper config %q", viperConfig)
		actualFile := viper.ConfigFileUsed()
		if actualFile != "" && actualFile != viperConfig {
			errorPrefix = fmt.Sprintf("%s = %q", errorPrefix, actualFile)
		}
		return errors.Wrap(err, errorPrefix)
	}

	if err := viper.ReadInConfig(); err != nil {
		// If the user specified a file suffix, the Viper won't
		// find the file because it always appends its known set
		// of file suffices. Therefore try once more without
		// suffix.
		ext := filepath.Ext(viperConfig)
		if _, ok := err.(viper.ConfigFileNotFoundError); ok && ext != "" {
			viper.SetConfigName(filepath.Base(viperConfig[0 : len(viperConfig)-len(ext)]))
			err = viper.ReadInConfig()
		}
		if err != nil {
			// If a config was required, then parsing must
			// succeed. This catches syntax errors and
			// "file not found". Unfortunately error
			// messages are sometimes hard to understand,
			// so try to help the user a bit.
			switch err.(type) {
			case viper.ConfigFileNotFoundError:
				if required {
					return wrapError(errors.New("not found"))
				}
				// Proceed without config.
				return nil
			case viper.UnsupportedConfigError:
				if required {
					return wrapError(errors.New("not using a supported file format"))
				}
				// Proceed without config.
				return nil
			default:
				// Something isn't right in the file.
				return wrapError(err)
			}
		}
	}

	// Update all flag values not already set with values found
	// via Viper. We do this ourselves instead of calling
	// something like viper.Unmarshal(&TestContext) because we
	// want to support all values, regardless where they are
	// stored.
	return wrapError(viperUnmarshal(flags))
}
// viperizeFlags checks whether a configuration file was specified,
// reads it, and updates the configuration variables in the specified
// flag set accordingly. Must be called after framework.HandleFlags()
// and before framework.AfterReadingAllFlags().
//
// The logic is so that a required configuration file must be present. If empty,
// the optional configuration file is used instead, unless also empty.
//
// Files can be specified with just a base name ("e2e", matches "e2e.json/yaml/..." in
// the current directory) or with path and suffix.
viperizeFlags checks whether a configuration file was specified,
reads it, and updates the configuration variables in the specified
flag set accordingly. Must be called after framework.HandleFlags()
and before framework.AfterReadingAllFlags().

The logic is so that a required configuration file must be present. If empty,
the optional configuration file is used instead, unless also empty.

Files can be specified with just a base name ("e2e", matches "e2e.json/yaml/..." in
the current directory) or with path and suffix.
// viperizeFlags checks whether a configuration file was specified // reads it and updates the configuration variables in the specified // flag set accordingly . Must be called after framework . HandleFlags () // and before framework . AfterReadingAllFlags () . // // The logic is so that a required configuration file must be present . If empty // the optional configuration file is used instead unless also empty . // // Files can be specified with just a base name ( " e2e " matches " e2e . json / yaml / ... " in // the current directory ) or with path and suffix .
func viperizeFlags(requiredConfig, optionalConfig string, flags *flag.FlagSet) error {
	viperConfig := optionalConfig
	required := false
	if requiredConfig != "" {
		viperConfig = requiredConfig
		required = true
	}
	if viperConfig == "" {
		return nil
	}
	viper.SetConfigName(filepath.Base(viperConfig))
	viper.AddConfigPath(filepath.Dir(viperConfig))
	wrapError := func(err error) error {
		if err == nil {
			return nil
		}
		errorPrefix := fmt.Sprintf("viper config %q", viperConfig)
		actualFile := viper.ConfigFileUsed()
		if actualFile != "" && actualFile != viperConfig {
			errorPrefix = fmt.Sprintf("%s = %q", errorPrefix, actualFile)
		}
		return errors.Wrap(err, errorPrefix)
	}
	if err := viper.ReadInConfig(); err != nil {
		ext := filepath.Ext(viperConfig)
		if _, ok := err.(viper.ConfigFileNotFoundError); ok && ext != "" {
			viper.SetConfigName(filepath.Base(viperConfig[0 : len(viperConfig)-len(ext)]))
			err = viper.ReadInConfig()
		}
		if err != nil {
			switch err.(type) {
			case viper.ConfigFileNotFoundError:
				if required {
					return wrapError(errors.New("not found"))
				}
				return nil
			case viper.UnsupportedConfigError:
				if required {
					return wrapError(errors.New("not using a supported file format"))
				}
				return nil
			default:
				return wrapError(err)
			}
		}
	}
	return wrapError(viperUnmarshal(flags))
}
func viperizeFlags ( requiredConfig , optionalConfig string , flags * flag . FlagSet ) error { viperConfig := optionalConfig required := false if requiredConfig != " " { viperConfig = requiredConfig required = true } if viperConfig == " " { return nil } viper . SetConfigName ( filepath . Base ( viperConfig ) ) viper . AddConfigPath ( filepath . Dir ( viperConfig ) ) wrapError := func ( err error ) error { if err == nil { return nil } errorPrefix := fmt . Sprintf ( " " , viperConfig ) actualFile := viper . ConfigFileUsed ( ) if actualFile != " " && actualFile != viperConfig { errorPrefix = fmt . Sprintf ( " " , errorPrefix , actualFile ) } return errors . Wrap ( err , errorPrefix ) } if err := viper . ReadInConfig ( ) ; err != nil { ext := filepath . Ext ( viperConfig ) if _ , ok := err . ( viper . ConfigFileNotFoundError ) ; ok && ext != " " { viper . SetConfigName ( filepath . Base ( viperConfig [ 0 : len ( viperConfig ) - len ( ext ) ] ) ) err = viper . ReadInConfig ( ) } if err != nil { switch err . ( type ) { case viper . ConfigFileNotFoundError : if required { return wrapError ( errors . New ( " " ) ) } return nil case viper . UnsupportedConfigError : if required { return wrapError ( errors . New ( " " ) ) } return nil default : return wrapError ( err ) } } } return wrapError ( viperUnmarshal ( flags ) ) }
viperizeFlags checks whether a configuration file was specified,
reads it, and updates the configuration variables in the specified
flag set accordingly.
viperizeFlags checks whether a configuration file was specified reads it and updates the configuration variables in the specified flag set accordingly .
// If the user specified a file suffix, the Viper won't // find the file because it always appends its known set // of file suffices. Therefore try once more without // suffix. // If a config was required, then parsing must // succeed. This catches syntax errors and // "file not found". Unfortunately error // messages are sometimes hard to understand, // so try to help the user a bit. // Proceed without config. // Proceed without config. // Something isn't right in the file. // Update all flag values not already set with values found // via Viper. We do this ourselves instead of calling // something like viper.Unmarshal(&TestContext) because we // want to support all values, regardless where they are // stored.