Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow directories with white-spaces to be passed #63

Merged
merged 6 commits into from
Dec 21, 2023
Merged
12 changes: 11 additions & 1 deletion run-clang-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import subprocess
import sys
import traceback
import re
from distutils.util import strtobool

from functools import partial
Expand Down Expand Up @@ -241,14 +242,23 @@ def print_trouble(prog, message, use_colors):
error_text = bold_red(error_text)
print("{}: {} {}".format(prog, error_text, message), file=sys.stderr)

def normalize_paths(paths):
"""
Normalizes backward slashes in each path in list of paths
Ex)
"features/Test\ Features/feature.cpp" => "features/Test Features/feature.cpp"
"""
return [path.replace("\\","") for path in paths]

def split_list_arg(arg):
"""
If arg is a list containing a single argument it is split into multiple elements.
Otherwise it is returned unchanged
Workaround for GHA not allowing list arguments
"""
return arg[0].split() if len(arg) == 1 else arg
# pattern matches all whitespaces except those preceded by a backslash, '\'
pattern = r'(?<!\\)\s+'
return normalize_paths(re.split(pattern, arg[0])) if len(arg) == 1 else arg


def main():
Expand Down