【问题标题】:Clang-Format: How to specify a custom format options file?Clang-Format:如何指定自定义格式选项文件?
【发布时间】:2018-07-28 12:02:24
【问题描述】:

我正在尝试为在 64 位 Windows 10 Pro 上运行的 clang-format v6.0.0 配置自定义样式选项文件。我首先使用以下命令行生成基于 llvm 样式的选项文件,该文件运行良好:

clang-format -style=llvm -dump-config > .clang-format

clang-format 的文档说明如下: “当所需的代码格式样式与可用选项不同时,可以使用 -style="{key: value, ...}" 选项或将样式配置放在 .clang-format 或 _clang 中自定义样式-format 项目目录中的文件,并使用 clang-format -style=file。"

因此,作为测试,我使用了上面生成的未更改的 .clang 格式文件,并使用了以下命令行:

clang-format -style=.clang-format Test.c

结果是一条消息说

"Invalid value for -style"

然后我将 .clang-format 的名称更改为 _clang-format 并再次尝试但结果相同。所以,我的问题是,“如何指定特定的样式选项文件?”

【问题讨论】:

  • 我的错误。 -style=file 表示使用实际的 word 文件,而不是替换所需文件的名称。我忽略了文件周围没有尖括号:

标签: clang-format


【解决方案1】:

正如您正确发现的那样,命令期待文字 -style=file。例如clang-format.exe -i -style=file -i 选项用于执行更改。 -style=file 告诉程序在当前目录中查找名为 .clang-format or _clang-format Configuration options 的配置文件。如果仍然找不到配置文件,程序将向上移动一个目录并继续搜索等等。更多命令行文档可以在here找到。

【讨论】:

    猜你喜欢
    • 2020-04-05
    • 2018-03-04
    • 2021-05-13
    • 2018-06-25
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    相关资源
    最近更新 更多