简体   繁体   中英

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

I am currently using NDesk.Options to manipulate my command line arguments. 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

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). This works "-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.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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