【问题标题】:Easy way to allow options only when other is present using CommandLineParserLibrary仅当使用 CommandLineParser 库存在其他选项时才允许选项的简单方法
【发布时间】:2019-03-25 14:02:02
【问题描述】:

我正在尝试使用这个库来实现逻辑: 我有动词write,以及这个方案的选项:

write (-md [-p|-s] [-t]) | (-txt [-v]) - '|' - 表示或(使用 -md 时仅接受 -p OR -s(但不是必需的,如 '[]' 所示))

有没有简单的方法来实现这个?还是我应该将其拆分为单独的动词?

【问题讨论】:

    标签: c# command-line-parser


    【解决方案1】:

    很抱歉回答自己的问题,但对其他人有帮助 (source):

    您可以在声明 OptionAttribute 时使用 SetName 参数:

    internal class Options
    {
        [Option("username", SetName = "auth")]
        public string Username { get; set; }
    
        [Option("password", SetName = "auth")]
        public string Password { get; set; }
    
        [Option("guestaccess", SetName = "guest")]
        public bool GuestAccess { get; set; }
    }
    

    现在usernamepassword 可以一起使用,但guestaccess 在“guest”集中单独使用,因此不能与其他集中的选项一起使用。

    【讨论】:

      猜你喜欢
      • 2019-09-17
      • 2018-04-06
      • 1970-01-01
      • 2022-07-13
      • 2015-08-15
      • 2019-08-14
      • 2017-04-02
      • 1970-01-01
      • 2021-06-03
      相关资源
      最近更新 更多