// matchVariableOrCommand attempts to match a string token to the prefix of a Command.
558312
func matchVariableOrCommand(v variables, token string) string {
	token = strings.ToLower(token)
	found := ""
	for cmd := range pprofCommands {
		if strings.HasPrefix(cmd, token) {
			if found != "" {
				return ""
			}
			found = cmd
		}
	}
	for variable := range v {
		if strings.HasPrefix(variable, token) {
			if found != "" {
				return ""
			}
			found = variable
		}
	}
	return found
}
677198
func BuildBindVariables(in map[string]interface{}) (map[string]*querypb.BindVariable, error) {
	if len(in) == 0 {
		return nil, nil
	}

	out := make(map[string]*querypb.BindVariable, len(in))
	for k, v := range in {
		bv, err := BuildBindVariable(v)
		if err != nil {
			return nil, fmt.Errorf("%s: %v", k, err)
		}
		out[k] = bv
	}
	return out, nil
}
1169794
func (s *Service) ReplaceVariable(ctx context.Context, variable *influxdb.Variable) error {
	return s.kv.Update(ctx, func(tx Tx) error {
		if err := s.putVariableOrgsIndex(ctx, tx, variable); err != nil {
			return &influxdb.Error{
				Err: err,
			}
		}
		return s.putVariable(ctx, tx, variable)
	})
}
83391
func subVars(s string, vars map[string]string) (string, error) {
	var badKeys []string
	res := subVarsRe.ReplaceAllStringFunc(s, func(match string) string {
		// Strip '${' and '}'.
		key := match[2 : len(match)-1]
		val, ok := vars[key]
		if !ok {
			badKeys = append(badKeys, key)
			return match
		}
		return val
	})
	if len(badKeys) != 0 {
		return res, fmt.Errorf("values for some variables are not provided: %v", badKeys)
	}
	return res, nil
}
323860
func getVariable(image *api.Image, name string) string {
	envName := name + "="
	for _, v := range image.Config.Env {
		if strings.HasPrefix(v, envName) {
			return strings.TrimSpace(v[len(envName):])
		}
	}

	return ""
}
880813
func (m *IncomingMessage) GetCommand() (string, string) {
	text := m.Text

	if !strings.HasPrefix(text, "/") {
		return "", text
	}
	r, _ := regexp.Compile("^/([a-zA-Z0-9_]+)(?:@[a-zA-Z0-9_]+)?.?(.*)?$")
	match := r.FindStringSubmatch(text)
	if len(match) == 3 {
		return match[1], match[2]
	} else if len(match) == 2 {
		return match[1], ""
	}
	return "", ""

}
302962
func (rules *Rules) FindVariable(path string) (*Variable, error) {
	if len(path) <= 1 {
		return nil, ErrorMap[ErrInvalidPath]
	}

	rule, err := rules.FindParentRule(path)
	if err != nil {
		return nil, err
	}

	sep := "/"
	segments := strings.Split(path, sep)
	variableName := strings.ToLower(segments[len(segments)-1])
	for _, variable := range rule.Variables {
		if strings.ToLower(variable.Name) == variableName {
			return variable, nil
		}
	}

	return nil, ErrorMap[ErrVariableNotFound]
}
1176094
func (c *Commands) Find(cmdstr string, prefix cmdPrefix) cmdfunc {
	// If <enter> use last command, if there was one.
	if cmdstr == "" {
		if c.lastCmd != nil {
			return c.lastCmd
		}
		return nullCommand
	}

	for _, v := range c.cmds {
		if v.match(cmdstr) {
			if prefix != noPrefix && v.allowedPrefixes&prefix == 0 {
				continue
			}
			c.lastCmd = v.cmdFn
			return v.cmdFn
		}
	}

	return noCmdAvailable
}
194393
func (ln *line) isVariable() bool {
	if !ln.isTopIndent() {
		return false
	}

	_, _, err := variableNV(ln)

	return err == nil
}
589889
func match(commandName string, args []interface{}, cmd *Cmd) bool {
	if commandName != cmd.Name || len(args) != len(cmd.Args) {
		return false
	}

	for pos := range cmd.Args {
		if implementsFuzzy(cmd.Args[pos]) {
			if cmd.Args[pos].(FuzzyMatcher).Match(args[pos]) == false {
				return false
			}
		} else if reflect.DeepEqual(cmd.Args[pos], args[pos]) == false {
			return false
		}

	}
	return true
}
77867
func ValidateBindVariables(bv map[string]*querypb.BindVariable) error {
	for k, v := range bv {
		if err := ValidateBindVariable(v); err != nil {
			return fmt.Errorf("%s: %v", k, err)
		}
	}
	return nil
}
566496
func (r *Remote) CommandFunc(m MatcherFunc, f CommandFunc) {
	r.service.HandleCommand(m, f)
}
432218
func (t *precompilationTypeChecker) AcceptVariable(v tree.Variable) {
	t.result = fmt.Errorf("no variables allowed - this is probably a programmer error: %s", v.Name)
}
729655
func BindVariablesEqual(x, y map[string]*querypb.BindVariable) bool {
	return proto.Equal(&querypb.BoundQuery{BindVariables: x}, &querypb.BoundQuery{BindVariables: y})
}
28679
func parseCommandLine(input []string) ([]string, variables, error) {
	cmd, args := input[:1], input[1:]
	name := cmd[0]

	c := pprofCommands[name]
	if c == nil {
		// Attempt splitting digits on abbreviated commands (eg top10)
		if d := tailDigitsRE.FindString(name); d != "" && d != name {
			name = name[:len(name)-len(d)]
			cmd[0], args = name, append([]string{d}, args...)
			c = pprofCommands[name]
		}
	}
	if c == nil {
		return nil, nil, fmt.Errorf("unrecognized command: %q", name)
	}

	if c.hasParam {
		if len(args) == 0 {
			return nil, nil, fmt.Errorf("command %s requires an argument", name)
		}
		cmd = append(cmd, args[0])
		args = args[1:]
	}

	// Copy the variables as options set in the command line are not persistent.
	vcopy := pprofVariables.makeCopy()

	var focus, ignore string
	for i := 0; i < len(args); i++ {
		t := args[i]
		if _, err := strconv.ParseInt(t, 10, 32); err == nil {
			vcopy.set("nodecount", t)
			continue
		}
		switch t[0] {
		case '>':
			outputFile := t[1:]
			if outputFile == "" {
				i++
				if i >= len(args) {
					return nil, nil, fmt.Errorf("unexpected end of line after >")
				}
				outputFile = args[i]
			}
			vcopy.set("output", outputFile)
		case '-':
			if t == "--cum" || t == "-cum" {
				vcopy.set("cum", "t")
				continue
			}
			ignore = catRegex(ignore, t[1:])
		default:
			focus = catRegex(focus, t)
		}
	}

	if name == "tags" {
		updateFocusIgnore(vcopy, "tag", focus, ignore)
	} else {
		updateFocusIgnore(vcopy, "", focus, ignore)
	}

	if vcopy["nodecount"].intValue() == -1 && (name == "text" || name == "top") {
		vcopy.set("nodecount", "10")
	}

	return cmd, vcopy, nil
}
836207
func RegexMatch(regexStr string) gopter.Gen {
	regexSyntax, err1 := syntax.Parse(regexStr, syntax.Perl)
	regex, err2 := regexp.Compile(regexStr)
	if err1 != nil || err2 != nil {
		return Fail(reflect.TypeOf(""))
	}
	return regexMatchGen(regexSyntax.Simplify()).SuchThat(func(v string) bool {
		return regex.MatchString(v)
	}).WithShrinker(StringShrinker)
}
705063
func (p *Parser) ParseVarRef() (*VarRef, error) {
	// Parse the segments of the variable ref.
	segments, err := p.parseSegmentedIdents()
	if err != nil {
		return nil, err
	}

	var dtype DataType
	if tok, _, _ := p.Scan(); tok == DOUBLECOLON {
		tok, pos, lit := p.Scan()
		switch tok {
		case IDENT:
			switch strings.ToLower(lit) {
			case "float":
				dtype = Float
			case "integer":
				dtype = Integer
			case "unsigned":
				dtype = Unsigned
			case "string":
				dtype = String
			case "boolean":
				dtype = Boolean
			default:
				return nil, newParseError(tokstr(tok, lit), []string{"float", "integer", "unsigned", "string", "boolean", "field", "tag"}, pos)
			}
		case FIELD:
			dtype = AnyField
		case TAG:
			dtype = Tag
		default:
			return nil, newParseError(tokstr(tok, lit), []string{"float", "integer", "string", "boolean", "field", "tag"}, pos)
		}
	} else {
		p.Unscan()
	}

	vr := &VarRef{Val: strings.Join(segments, "."), Type: dtype}

	return vr, nil
}