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

时间:2020-10-01 13:54:15

标签: c++ llvm

我正在使用llvm CommandLine库在我的一个C ++项目中进行参数解析。它具有一个选项,可以接受多个日志记录级别,其类型为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)
        );

如何从用户帮助字符串(enum的输出)中隐藏特定的-help值,但仍然继续接受它?在这种情况下,我想从用户帮助字符串中隐藏“跟踪”,并且仍然继续接受--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

1 个答案:

答案 0 :(得分:2)

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();
     }

     // ...
 };
给定选项的

mods(在OP中为 values )不能单独拥有帮助可见性选项;即没有自己的cl::OptionHidden状态。

我似乎唯一隐藏trace选项变体的解决方法是从trace选项中删除verbose值并将其创建为独立的{{1 }}选项,没有值/模数,例如Hidden

相关问题