code: func (c *Config) NewSubViper(flags *pflag.FlagSet, cfg interface{}) (*viper.Viper, error) {
  	v := viper.New()
  
  	if flags != nil {
  		if err := v.BindPFlags(flags); err != nil {
  			return nil, err
  		}
  	}
  
  	if err := c.ConfigureViper(v); err != nil {
  		return nil, err
  	}
  
  	// Use the env from the config if it's not explicitly set
  	env := c.LoadEnv
  	if env == "" {
  		env = v.GetString("env")
  	}
  
  	v = v.Sub(env)
  	if v == nil {
  		return nil, fmt.Errorf("cannot find env section named %s", env)
  	}
  
  	mappings, err := GetTagMappings(cfg)
  	if err != nil {
  		return nil, errors.Wrap(err, "unable to get tag mappings for config struct")
  	}
  
  	if c.EnvPrefix != "" {
  		for _, m := range mappings {
  			v.BindEnv(m.chain, strings.Join([]string{c.EnvPrefix, m.env}, "_"))
  		}
  	} else {
  		for _, m := range mappings {
  			v.BindEnv(m.chain, m.env)
  		}
  	}
  
  	if v == nil {
  		return nil, fmt.Errorf("unable to load environment %q from %q", env, c.File)
  	}
  
  	if flags != nil {
  		if err := v.BindPFlags(flags); err != nil {
  			return nil, err
  		}
  	}
  
  	v.Set("env", env)
  	return v, nil
  }
docs: // NewSubViper returns a viper instance activated against the active environment
  // configuration subsection and initialized with the config.toml
  // configuration file and the environment variable prefix.
  // It also takes in the configuration struct so that it can generate the env
  // mappings.