// NewEnv returns a new Env
169113
func NewEnv(v interface{}) (*Env, error) {
	e := &Env{}

	if reflect.TypeOf(v).Kind() != reflect.Ptr {
		return nil, errInvalidValue
	}
	if reflect.ValueOf(v).Elem().Kind() != reflect.Struct {
		return nil, errInvalidValue
	}

	e.SetValue(v)

	if err := e.Parse(); err != nil {
		return e, err
	}

	return e, nil
}
1345058
func mergeEnv(sysEnv []string, cmdEnv map[string]string) []string {

	// sort keys so that duplicates are filtered in deterministic order
	keys := make([]string, 0, len(cmdEnv))
	for k := range cmdEnv {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	var env []string
	seen := make(map[string]bool) // seen env keys

	// add vars from cmdEnv - skipping duplicates
	for _, k := range keys {
		v := cmdEnv[k] // value
		uk := strings.ToUpper(k)
		if !seen[uk] {
			env = append(env, k+"="+v)
			seen[uk] = true
		}
	}
	// add vars from sysEnv - skipping duplicates and keys present in cmdEnv
	for _, kv := range sysEnv {
		if n := strings.IndexByte(kv, '='); n != -1 {
			k := kv[:n] // key
			uk := strings.ToUpper(k)
			if !seen[uk] {
				env = append(env, kv)
				seen[uk] = true
			}
		}
	}
	return env
}
302745
func GetAppEnv() (AppEnv, error) {
	appEnv := AppEnv{}
	if err := env.Populate(&appEnv); err != nil {
		return AppEnv{}, err
	}
	return appEnv, nil
}
395091
func (r *Application) AddEnv(name, value string) *Application {
	if r.Env == nil {
		r.EmptyEnvs()
	}
	(*r.Env)[name] = value

	return r
}
390794
func (kv *KeyValSlice) SetEnv(v string) error {
	if err := json.Unmarshal([]byte(v), &kv); err != nil {
		return trace.Wrap(
			err, "failed to parse environment variable, expected JSON map")
	}
	return nil
}
1192175
func (c *Configuration) CheckEnv() error {
	if c.ActiveEnv == "" {
		return fmt.Errorf("No active environment chosen. Please choose an environment using the \"env\" flag in config.toml or the $%s_ENV environment variable", c.AppEnvName)
	}
	return nil
}
1338219
func Env() Environment {
	switch {
	case os.Getenv("CI") == "true" && os.Getenv("TRAVIS") == "true":
		return Environment{
			Name:          "travis",
			Repo:          os.Getenv("TRAVIS_REPO_SLUG"),
			Commit:        os.Getenv("TRAVIS_COMMIT"),
			Branch:        os.Getenv("TRAVIS_BRANCH"),
			Tag:           os.Getenv("TRAVIS_TAG"),
			Buildnum:      os.Getenv("TRAVIS_BUILD_NUMBER"),
			IsPullRequest: os.Getenv("TRAVIS_PULL_REQUEST") != "false",
			IsCronJob:     os.Getenv("TRAVIS_EVENT_TYPE") == "cron",
		}
	case os.Getenv("CI") == "True" && os.Getenv("APPVEYOR") == "True":
		return Environment{
			Name:          "appveyor",
			Repo:          os.Getenv("APPVEYOR_REPO_NAME"),
			Commit:        os.Getenv("APPVEYOR_REPO_COMMIT"),
			Branch:        os.Getenv("APPVEYOR_REPO_BRANCH"),
			Tag:           os.Getenv("APPVEYOR_REPO_TAG_NAME"),
			Buildnum:      os.Getenv("APPVEYOR_BUILD_NUMBER"),
			IsPullRequest: os.Getenv("APPVEYOR_PULL_REQUEST_NUMBER") != "",
			IsCronJob:     os.Getenv("APPVEYOR_SCHEDULED_BUILD") == "True",
		}
	default:
		return LocalEnv()
	}
}
30528
func AddEnv(env_str string) error {
	result := regexp.MustCompile("([^:]+):([^=]+)=(.+)").FindStringSubmatch(env_str)
	if result==nil {
		return fmt.Errorf("Error parsing internal service environment variable: %s", env_str)
	}
	service := result[1]
	key     := result[2]
	val     := result[3]

	if serviceMap, ok := envPerService[service]; ok {
		serviceMap[key] = val
		return nil
	}
	svcNames := []string{}
	for key := range envPerService {
		svcNames = append(svcNames, key)
	}
	return fmt.Errorf("Error setting internal service environment:'%s'  Service '%s' must be one of [%s]'",
		env_str, service, strings.Join(svcNames, ", "))
}
480866
func NewEnvSource(prefix string, env ...string) Source {
	vars := makeEnvVars(env)
	base := make([]string, 0, 10)

	if prefix != "" {
		base = append(base, prefix)
	}

	return SourceFunc(func(dst Map) (err error) {
		dst.Scan(func(path []string, item MapItem) {
			path = append(base, path...)
			path = append(path, item.Name)

			k := snakecaseUpper(strings.Join(path, "_"))

			if v, ok := vars[k]; ok {
				if e := item.Value.Set(v); e != nil {
					err = e
				}
			}
		})
		return
	})
}
492728
func WithEnv(environmentVariables []string) SpecOpts {
	return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
		if len(environmentVariables) > 0 {
			setProcess(s)
			s.Process.Env = replaceOrAppendEnvValues(s.Process.Env, environmentVariables)
		}
		return nil
	}
}
1198661
func Env(env []string) map[string]string {
	vars := mapEnv(env, splitEnv)
	return vars
}
574498
func NewBackend() backend.Backend {
	return backend.Func("env", func(ctx context.Context, key string) ([]byte, error) {
		val, ok := os.LookupEnv(key)
		if ok {
			return []byte(val), nil
		}

		key = strings.Replace(strings.ToUpper(key), "-", "_", -1)

		val, ok = os.LookupEnv(key)
		if ok {
			return []byte(val), nil
		}

		return nil, backend.ErrNotFound
	})
}
1133198
func (opts *Options) SetEnv(value *Env) {
	opts.env = value

	C.rocksdb_options_set_env(opts.c, value.c)
}
1225918
func NewEnvironment(ctx context.Context) *Environment {
	ctx, cancel := context.WithCancel(ctx)
	e := &Environment{
		ctx:       ctx,
		cancel:    cancel,
		generator: NewIDGenerator(),
		stopCh:    make(chan struct{}),
	}
	return e
}
110926
func Env(env expand.Environ) func(*Runner) error {
	return func(r *Runner) error {
		if env == nil {
			env = expand.ListEnviron(os.Environ()...)
		}
		r.Env = env
		return nil
	}
}
756875
func mergeEnvWin(current, newValues map[string]string) map[string]string {
	uppers := make(map[string]string, len(current))
	news := map[string]string{}
	for k, v := range current {
		uppers[strings.ToUpper(k)] = v
	}

	for k, v := range newValues {
		up := strings.ToUpper(k)
		if _, ok := uppers[up]; ok {
			uppers[up] = v
		} else {
			news[k] = v
		}
	}

	for k := range current {
		current[k] = uppers[strings.ToUpper(k)]
	}
	for k, v := range news {
		current[k] = v
	}
	return current
}
403256
func LocalEnv() Environment {
	env := applyEnvFlags(Environment{Name: "local", Repo: "ethereum/go-ethereum"})

	head := readGitFile("HEAD")
	if splits := strings.Split(head, " "); len(splits) == 2 {
		head = splits[1]
	} else {
		return env
	}
	if env.Commit == "" {
		env.Commit = readGitFile(head)
	}
	if env.Branch == "" {
		if head != "HEAD" {
			env.Branch = strings.TrimPrefix(head, "refs/heads/")
		}
	}
	if info, err := os.Stat(".git/objects"); err == nil && info.IsDir() && env.Tag == "" {
		env.Tag = firstLine(RunGit("tag", "-l", "--points-at", "HEAD"))
	}
	return env
}