def substituteVariables(command, level, name, value, target=None, **kwargs):
    """Substitute variables in command fragments by values e.g. ${level} => 'warning'."""
    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
