// StringFlagOrEnv - returns the value of the flag if specified, otherwise the env's value.
// Empty string counts as not specified!
324280
func StringFlagOrEnv(flagValue *string, envKey string) string {
	if flagValue != nil && *flagValue != "" {
		return *flagValue
	}
	return os.Getenv(envKey)
}
1026088
func EnvFiltered(rx *regexp.Regexp) map[string]string {
	res := map[string]string{}
	for _, e := range os.Environ() {
		pair := strings.Split(e, "=")
		if rx.MatchString(pair[0]) {
			res[pair[0]] = pair[1]
		}
	}
	return res
}
395091
func (r *Application) AddEnv(name, value string) *Application {
	if r.Env == nil {
		r.EmptyEnvs()
	}
	(*r.Env)[name] = value

	return r
}
311491
func ParseEnv(env []string) (map[string]string, error) {
	m := make(map[string]string)

	for _, s := range env {
		parts := strings.SplitN(s, "=", 2)
		if len(parts) == 2 {
			m[parts[0]] = parts[1]
		} else {
			return nil, fmt.Errorf("environment variable %q is missing a value", parts[0])
		}
	}

	return m, nil
}
367018
func env(b *Builder, args []string, attributes map[string]bool, flagArgs []string, original string) error {
	if len(args) == 0 {
		return errAtLeastOneArgument("ENV")
	}

	if len(args)%2 != 0 {
		// should never get here, but just in case
		return errTooManyArguments("ENV")
	}

	// TODO/FIXME/NOT USED
	// Just here to show how to use the builder flags stuff within the
	// context of a builder command. Will remove once we actually add
	// a builder command to something!
	/*
		flBool1 := b.flags.AddBool("bool1", false)
		flStr1 := b.flags.AddString("str1", "HI")

		if err := b.flags.Parse(); err != nil {
			return err
		}

		fmt.Printf("Bool1:%v\n", flBool1)
		fmt.Printf("Str1:%v\n", flStr1)
	*/

	for j := 0; j < len(args); j++ {
		// name  ==> args[j]
		// value ==> args[j+1]
		newVar := args[j] + "=" + args[j+1] + ""
		gotOne := false
		for i, envVar := range b.RunConfig.Env {
			envParts := strings.SplitN(envVar, "=", 2)
			if envParts[0] == args[j] {
				b.RunConfig.Env[i] = newVar
				b.Env = append([]string{newVar}, b.Env...)
				gotOne = true
				break
			}
		}
		if !gotOne {
			b.RunConfig.Env = append(b.RunConfig.Env, newVar)
			b.Env = append([]string{newVar}, b.Env...)
		}
		j++
	}

	return nil
}
375611
func ValidateEnvironment(wenv map[string]string) (r results) {
	for wkey, wval := range wenv {
		gval := os.Getenv(wkey)
		if gval != wval {
			err := fmt.Errorf("environment variable %q not set appropriately (need %q, got %q)", wkey, wval, gval)
			r = append(r, err)
		}
	}
	return
}
809211
func setFlagFromEnv(name, envar string, fs *pflag.FlagSet) {
	if fs.Changed(name) {
		return
	}
	if v, ok := os.LookupEnv(envar); ok {
		fs.Set(name, v)
	}
}
54211
func envFlag(usage string, required bool) cli.Flag {
	return newPlaceholder("environment, e", "ENV", usage, "", "TORUS_ENVIRONMENT", required)
}
334839
func flagTypeArrayVal(a *design.AttributeDefinition, field string) string {
	switch a.Type.ToArray().ElemType.Type {
	case design.Number, design.Boolean, design.UUID, design.DateTime, design.Any:
		return "%s"
	}
	return field
}
1281246
func ContextFromString(value string) (SpanContext, error) {
	var context SpanContext
	if value == "" {
		return emptyContext, errEmptyTracerStateString
	}
	parts := strings.Split(value, ":")
	if len(parts) != 4 {
		return emptyContext, errMalformedTracerStateString
	}
	var err error
	if context.traceID, err = TraceIDFromString(parts[0]); err != nil {
		return emptyContext, err
	}
	if context.spanID, err = SpanIDFromString(parts[1]); err != nil {
		return emptyContext, err
	}
	if context.parentID, err = SpanIDFromString(parts[2]); err != nil {
		return emptyContext, err
	}
	flags, err := strconv.ParseUint(parts[3], 10, 8)
	if err != nil {
		return emptyContext, err
	}
	context.flags = byte(flags)
	return context, nil
}
1098019
func (c *ServerContext) GetEnv(key string) (string, bool) {
	val, ok := c.env[key]
	return val, ok
}
204640
func Env(m map[string]string) (env []string) {
	for k, v := range m {
		env = append(env, fmt.Sprintf("%s=%s", k, v))
	}
	return
}
1061562
func (f *FlagSet) String(name string, value string, usage string) *string {
	p := new(string)
	f.StringVar(p, name, value, usage)
	return p
}
223858
func GoEnv(name, line string) (value string, ok bool) {
	// Remove any leading "set " found on windows.
	// Match the name to the env var + "=".
	// Remove any quotes.
	// Return result.
	line = strings.TrimPrefix(line, "set ")
	if len(line) < len(name)+1 {
		return "", false
	}
	if name != line[:len(name)] || line[len(name)] != '=' {
		return "", false
	}
	line = line[len(name)+1:]
	if un, err := strconv.Unquote(line); err == nil {
		line = un
	}
	return line, true
}
32174
func (c Flags) String(name string) string {
	f := c.Get(name)
	if f == nil {
		return ""
	}
	return *f.Value.(*string) //*f.Value if string
}
1354248
func StringRGBA(renderer *sdl.Renderer, x, y int32, s string, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_s := C.CString(s)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.stringRGBA((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x, _y, _s, _r, _g, _b, _a) == 0
}
185272
func (f *FlagClause) NoEnvar() *FlagClause {
	f.envar = ""
	f.noEnvar = true
	return f
}