func viperUnmarshal(flags *flag.FlagSet) error {
	var result error
	set := make(map[string]bool)

	// Determine which values were already set explicitly via
	// flags. Those we don't overwrite because command line
	// flags have a higher priority.
	flags.Visit(func(f *flag.Flag) {
		set[f.Name] = true
	})

	flags.VisitAll(func(f *flag.Flag) {
		if result != nil ||
			set[f.Name] ||
			!viper.IsSet(f.Name) {
			return
		}

		// In contrast to viper.Unmarshal(), values
		// that have the wrong type (for example, a
		// list instead of a plain string) will not
		// trigger an error here. This could be fixed
		// by checking the type ourselves, but
		// probably isn't worth the effort.
		//
		// "%v" correctly turns bool, int, strings into
		// the representation expected by flag, so those
		// can be used in config files. Plain strings
		// always work there, just as on the command line.
		str := fmt.Sprintf("%v", viper.Get(f.Name))
		if err := f.Value.Set(str); err != nil {
			result = fmt.Errorf("setting option %q from config file value: %s", f.Name, err)
		}
	})

	return result
}
// viperUnmarshall updates all flags with the corresponding values found
// via Viper, regardless whether the flag value is stored in TestContext, some other
// context or a local variable.
viperUnmarshall updates all flags with the corresponding values found
via Viper, regardless whether the flag value is stored in TestContext, some other
context or a local variable.
// viperUnmarshall updates all flags with the corresponding values found // via Viper regardless whether the flag value is stored in TestContext some other // context or a local variable .
func viperUnmarshal(flags *flag.FlagSet) error {
	var result error
	set := make(map[string]bool)
	flags.Visit(func(f *flag.Flag) {
		set[f.Name] = true
	})
	flags.VisitAll(func(f *flag.Flag) {
		if result != nil ||
			set[f.Name] ||
			!viper.IsSet(f.Name) {
			return
		}
		 "%v" correctly turns bool, int, strings into
		 the representation expected by flag, so those
		 can be used in config files. Plain strings
		 always work there, just as on the command line.
		str := fmt.Sprintf("%v", viper.Get(f.Name))
		if err := f.Value.Set(str); err != nil {
			result = fmt.Errorf("setting option %q from config file value: %s", f.Name, err)
		}
	})
	return result
}
func viperUnmarshal ( flags * flag . FlagSet ) error { var result error set := make ( map [ string ] bool ) flags . Visit ( func ( f * flag . Flag ) { set [ f . Name ] = true } ) flags . VisitAll ( func ( f * flag . Flag ) { if result != nil || set [ f . Name ] || ! viper . IsSet ( f . Name ) { return } str := fmt . Sprintf ( " " , viper . Get ( f . Name ) ) if err := f . Value . Set ( str ) ; err != nil { result = fmt . Errorf ( " " , f . Name , err ) } } ) return result }
viperUnmarshall updates all flags with the corresponding values found
via Viper, regardless whether the flag value is stored in TestContext, some other
context or a local variable.
viperUnmarshall updates all flags with the corresponding values found via Viper regardless whether the flag value is stored in TestContext some other context or a local variable .
// Determine which values were already set explicitly via // flags. Those we don't overwrite because command line // flags have a higher priority. // In contrast to viper.Unmarshal(), values // that have the wrong type (for example, a // list instead of a plain string) will not // trigger an error here. This could be fixed // by checking the type ourselves, but // probably isn't worth the effort. // // "%v" correctly turns bool, int, strings into // the representation expected by flag, so those // can be used in config files. Plain strings // always work there, just as on the command line.