You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by GitBox <gi...@apache.org> on 2018/12/27 22:15:01 UTC

[GitHub] paroxayte opened a new pull request #28: add support priority based iteration over options supplied to CommandLine

paroxayte opened a new pull request #28: add support priority based iteration over options supplied to CommandLine
URL: https://github.com/apache/commons-cli/pull/28
 
 
   CommandLine stores the options parsed as ArrayList. I changed this to what is essentially an iterable priority queue. I tweaked a TreeSet to act like a priority queue due to iteration order not being guaranteed in a java.util.PriorityQueue instance. The advantage to this is that it reduces complexity on the user end. When order is important currently redundant tracking and management is required to orchestrate the execution order of operations based on provided flags and arguments. With this patch it is possible to easily orchestrate execution order easily eg:
   
   ```java
   // args = {"a", "b"}
   public static void main(String[] args) {
       Option op1 = Option.builder("a").priority(3);
       ...
       Option opN = Option.builder("b").build(99); // Iterator returns in a result of highest to lowest priority, and in a tie it is ordered as queue. 
         
       CommandLine cl = generateCL(ops, args);
       while(itr.hasNext()) {
         controlSwitch(itr.next());
       }
   }
   
   private static void controlSwitch(Option o) {
       String key = o.getKey();
       switch(key) {
         case "op1"
         ... // Do stuff in a knowable ordered fashion.
         case "opnN"
       }
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org