gpt4 book ai didi

c++ - 如何从 llvm 命令行帮助字符串中隐藏特定的枚举值?

转载 作者:行者123 更新时间:2023-12-03 06:54:28 25 4
gpt4 key购买 nike

我在我的一个 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::Hiddencl::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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com