Substitute variables in command fragments by values e.g. ${level} => 'warning'.
331729
def substitute_variables(command, level, name, value, target=None, **kwargs):
    """"""
    rule = kwargs.get('rule', {})
    rule_value = rule.get('value', '') if rule else ''
    substitutes = {
        '${level}': str(level),
        '${target}': str(target),
        '${name}': '"' + str(name) + '"',
        '${value}': str(value),
        '${limit_value}': str(rule_value),
    }

    result = command
    for pattern, value in substitutes.items():
        result = result.replace(pattern, value)

    return result
1093876
def replaceVariables(path, datetime=None, pathvars=None):
    """"""

    if datetime is None:
        datetime = time.gmtime()

    # if path variables are not given, set as empty list
    if pathvars is None:
        pathvars = [ ]

    # create an init path list to loop through
    if isinstance(path, list):
        path_list = path
    else:
        path_list = [ path ]

    # Set up the regex to search for variables
    regex = re.compile('\$\{(.*?)\}')

    # create a newpath list that will hold the 'cleaned' paths
    # with variables and strftime format directives replaced
    newpath_list = [ ]

    for p in path_list:
        # create temppath_list to be used a we work through the
        newpath_list.append(p)

        # Variable replacement
        # Find all the variables in path using the regex
        for k in regex.findall(p):
            # Check if the key is in path variables map
            if k in pathvars:
                # get the str or list of values
                v = pathvars[k]

                # Check value of variable must be in (string, integer, list)
                if type(v) is dict:
                    msg = "Path variable must refer to string, integer, or list"
                    raise TypeError(msg)

                # get the list of possible variable values
                value_list = v if type(v) is list else [ v ]


                # create temp_list for now
                temp_list = []

                # loop through the most recent newpath list
                # need to do this every time in order to account for all possible
                # combinations
                # replace the variables
                # loop through the list of values and replace the variables
                for v in value_list:
                    for newpath in newpath_list:
                        # remove the path from newpath_list
                        temp_list.append(newpath.replace('${%s}' % k, str(v)))

                # replace newpath_list
                newpath_list = temp_list

        # strftime translation
        # Loop through newpath_list to do strftime translation
        for index, newpath in enumerate(newpath_list):
            # Apply strftime translation
            newpath_list[index] = time.strftime(newpath, datetime)

    return newpath_list
1066851
function replaceVariables( value ) {

            return value.replace( options.variableRegex, function( match, key ) {

                if ( options.variables[ key ] === undefined ) {
                    grunt.log.warn( "No variable definition found for: " + key );
                    return "";
                }

                return options.variables[ key ];
            } );

        }
541474
def replace_command(command, broken, matched):
    """"""
    new_cmds = get_close_matches(broken, matched, cutoff=0.1)
    return [replace_argument(command.script, broken, new_cmd.strip())
            for new_cmd in new_cmds]
682434
private function replace_var( $matches ) {
		$cmd = $matches[0];

		foreach ( array_slice( $matches, 1 ) as $key ) {
			$cmd = str_replace( '{' . $key . '}', $this->variables[ $key ], $cmd );
		}

		return $cmd;
	}
2296
def cli(env):
    """"""
    filtered_vars = dict([(k, v)
                          for k, v in env.vars.items()
                          if not k.startswith('_')])
    env.fout(formatting.iter_to_table(filtered_vars))
1040328
function substituteVars(rawText, vars)
{
    if (!vars)
    {
        return rawText;
    }
    //after loading contents, perform variable substitution
    Object.keys(vars).forEach(function (varName)
    {
        if (vars.hasOwnProperty(varName))
        {
            var varValue = vars[varName];
            rawText = replaceAll(rawText, varName, varValue);
        }
    });
    return rawText;
}
411944
def _replace_variables(data, variables):
    """"""
    formatter = string.Formatter()
    return [formatter.vformat(item, [], variables) for item in data]
615860
function(nodePath, state) {
        var replacements = [];

        if ( nodePath.node.source.value.match(/^[\./]/) ) {
          nodePath.node.specifiers.forEach(function(specifier) {
            var expr = getGlobalExpression(
              state,
              removeExtensions(nodePath.node.source.value),
              specifier.imported ? specifier.imported.name : null,
              t.isImportNamespaceSpecifier(specifier)
            );
            replacements.push(t.variableDeclaration('var', [
              t.variableDeclarator(specifier.local, expr)
            ]));
          });
        }
        nodePath.replaceWithMultiple(replacements);
      }
453553
def substitute(self, var_map):
        
        if self in var_map:
            return var_map[self]
        return self._substitute(var_map)
1152721
function replaceEnvironmentVariables (fileContent) {
  const environmentVariable = new RegExp(/\${([^}]+)}/g)
  // eslint-disable-next-line
  fileContent = fileContent.replace(environmentVariable, (a, b) => process.env[b] || '')
  return fileContent
}
739102
public static String substitute(String input, List<VariableInstance> variables)
    throws MdwException {
        StringBuffer substituted = new StringBuffer(input.length());
        try {
            Matcher matcher = tokenPattern.matcher(input);
            int index = 0;
            while (matcher.find()) {
                String match = matcher.group();
                substituted.append(input.substring(index, matcher.start()));
                Object value = getVariableValue(match.substring(2, match.length() - 1), variables);
                if (value != null)
                    substituted.append(value);
                index = matcher.end();
            }
            substituted.append(input.substring(index));
            return substituted.toString();
        }
        catch (Exception ex) {
            throw new MdwException("Error substituting expression value(s) in input: '" + input + "'", ex);
        }
    }
895663
function envReplace(str, vars) {
  return str.replace(/\$?\$\{([A-Za-z0-9_]+)(:-(.*?))?\}/g, function (varStr, varName, _, defValue) {
    // Handle escaping:
    if (varStr.indexOf('$$') === 0) {
      return varStr;
    }
    // Handle simple variable replacement:
    if (vars.hasOwnProperty(varName)) {
      log.debug(`${varName} replaced in configuration file`);
      return vars[varName];
    }
    // Handle default values:
    if (defValue) {
      log.debug(`${varName} replaced with default value in configuration file`);
      return defValue;
    }
    log.warn(`Unknown variable: ${varName}. Returning null.`);
    return null;
  });
}
891849
def _PreParse(self, key, value):
        """"""
        if key == "Command":
            return re.sub(r"(\[\[.+?\]\])", self._Completion, value)
        else:
            return value
39515
def substitute_filename(fn, variables):
    
    for var, value in variables.items():
        fn = fn.replace('+%s+' % var, str(value))
    return fn
1110206
function VarCommand(value, engine) {
        var match = value.match(/^\s*([a-z0-9_]+)\s*=([\s\S]*)$/i);
        if (!match) {
            throw new Error('Invalid ' + this.type + ' syntax: ' + value);
        }

        this.name = match[1];
        this.expr = match[2];
        Command.call(this, value, engine);
        this.cloneProps = ['name', 'expr'];
    }
1021939
function FilterCommand(value, engine) {
        var match = value.match(/^\s*([a-z0-9_-]+)\s*(\(([\s\S]*)\))?\s*$/i);
        if (!match) {
            throw new Error('Invalid ' + this.type + ' syntax: ' + value);
        }

        this.name = match[1];
        this.args = match[3];
        Command.call(this, value, engine);
        this.cloneProps = ['name', 'args'];
    }