简体   繁体   English

使用NDesk.Options在命令行参数中标记优先级。 C#

[英]flags priority in command line arguments using NDesk.Options. C#

I am currently using NDesk.Options to manipulate my command line arguments. 我目前正在使用NDesk.Options来操纵命令行参数。 The problem I encountered now is that when I run with multiple flags, the computation is done in the order the flags appear. 我现在遇到的问题是,当我使用多个标志运行时,计算是按照标志出现的顺序进行的。 But this is not always what I want. 但这并不总是我想要的。 For example for these arguments 例如这些参数

-t 20 -g mailGroup -t 20 -g mailGroup

I want first the -g flag to be computed (which loads a mailGroup data) and just after it to compute the -t 20 (which is top 20 of some analysis). 我希望首先计算-g标志(加载一个mailGroup数据),然后紧接着计算-t 20(这是某些分析的前20个)。 This works "-g mailGroup -t 20" 这适用于“ -g mailGroup -t 20”

Also, my -t 20 will not work if nothing is loaded, so basically the -g mailGroup is a needed option before -t 20. 另外,如果未加载任何内容,我的-t 20将无法工作,因此,基本上-g mailGroup是-t 20之前的必需选项。

Is there an elegant way to provide priority of evaluation for these flags ? 有没有一种优雅的方法可以为这些标志提供优先级评估? Also maybe dealing with the cases that one flag requires the existence of a subset of another flags to be computed before it (like for example I have multiple ways and forms of loading, not just -g). 也可能处理一个标志需要在其之前计算另一个标志的子集的情况(例如,我有多种加载方式和形式,而不仅仅是-g)。

Are you performing logic in the action for each option (ie. at the same time you read each new option)? 您是否在每个选项的操作中执行逻辑(即,同时阅读每个新选项)? If so, decouple and simply set boolean/config variables within the actions, then do your logic after all options are parsed. 如果是这样,请在操作中解耦并简单地设置布尔值/配置变量,然后在解析所有选项后执行逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM