How to call clang-format over a cpp project folder?

后端 未结 9 2292
眼角桃花
眼角桃花 2021-01-29 21:43

Is there a way to call something like clang-format --style=Webkit for an entire cpp project folder, rather than running it separately for each file?

I am us

9条回答
  •  萌比男神i
    2021-01-29 21:51

    Unfortunately, there is no way to apply clang-format recursively. *.cpp will only match files in the current directory, not subdirectories. Even **/* doesn't work.

    Luckily, there is a solution: grab all the file names with the find command and pipe them in. For example, if you want to format all .h and .cpp files in the directory foo/bar/ recursively, you can do

    find foo/bar/ -iname *.h -o -iname *.cpp | xargs clang-format -i
    

    See here for additional discussion.

提交回复
热议问题