作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的一个 C++ 项目中使用 llvm CommandLine 库进行参数解析。它有一个接受多个日志级别的选项,它是 enum
类型,如下所示:
enum LogLevels {
error,
critical_warnings,
all_warnings,
info,
trace
};
cl::OptionCategory Logging("Verbose Options:");
cl::opt<LogLevels> verbose("logging", cl::desc("Control logging levels:"),
cl::values(
clEnumValN(error,"error-only", "Level:1 - Report fatal errors"),
clEnumValN(critical_warnings,"critical-warnings", "Level:2 - Report critical warnings and errors (default)"),
clEnumValN(all_warnings, "all-warnings", "Level:3 - Report all warnings and errors"),
clEnumValN(info, "info", "Level:4 - Report info messages along with error/warnings"),
clEnumValN(trace, "trace", "Level:5 - Report all internal/developer details in logs")),
cl::init(LogLevels::critical_warnings), cl::cat(Logging)
);
如何从用户帮助字符串(-help
的输出)中隐藏特定的 enum
值,但仍然继续接受它?在这种情况下,我想从用户帮助字符串中隐藏“trace”并仍然继续接受 --logging=trace
仅供内部使用。
我试着查看 https://llvm.org/docs/CommandLine.html#但想不通。我需要类似于 cl::Hidden
或 cl::ReallyHidden
修饰符的东西,但用于 enum
值。
-help
的当前输出是:
Verbose Options::
--logging=<value> - Control logging levels:
=error-only - Level:1 - Report fatal errors
=critical-warnings - Level:2 - Report critical warnings and errors (default)
=all-warnings - Level:3 - Report all warnings and errors
=info - Level:4 - Report info messages along with error/warnings
=trace - Level:5 - Report all internal/developer details in logs
最佳答案
OptionEnumValue
应用于整个选项,正如我们从 the constructor of the cl::opt
class template 中看到的那样
template <class DataType, bool ExternalStorage = false,
class ParserClass = parser<DataType>>
class opt : public Option,
public opt_storage<DataType, ExternalStorage,
std::is_class<DataType>::value> {
// ...
template <class... Mods>
explicit opt(const Mods &... Ms)
: Option(Optional, NotHidden), Parser(*this) {
apply(this, Ms...);
done();
}
// ...
};
给定选项的模组(值,在 OP 的上下文中)本身不能包含帮助可见性选项;即,没有自己的 cl::OptionHidden
状态。
我看起来好像隐藏 trace
选项变体的唯一解决方法是从 verbose
选项中删除 trace
值并创建它作为一个独立的隐藏
选项,没有值/mods,比如--logging_trace
。
关于c++ - 如何从 llvm 命令行帮助字符串中隐藏特定的枚举值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64156872/
我是一名优秀的程序员,十分优秀!