package picocli.examples.arggroup;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;

import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Command(name = "grades", mixinStandardHelpOptions = true, version = "grades 1.0")
public class Grades implements Runnable {

    // unfortunately this does not work, see https://github.com/remkop/picocli/issues/1027
//    static class StudentGrade {
//        @Parameters(index = "0") String name;
//        @Parameters(index = "1") BigDecimal grade;
//    }
//
//    @ArgGroup(exclusive = false, multiplicity = "1..*")
//    List<StudentGrade> gradeList;

    @Parameters(arity = "2",
            description = "Each pair must have a name and a grade.",
            paramLabel = "(NAME GRADE)...", hideParamSyntax = true)
    List<String> gradeList;

    @Override
    public void run() {
        System.out.println(gradeList);
        Map<String, BigDecimal> map = new LinkedHashMap<>();
        for (int i = 0; i < gradeList.size(); i += 2) {
            map.put(gradeList.get(i), new BigDecimal(gradeList.get(i + 1)));
        }
    }

    public static void main(String[] args) {
        int exitCode = new CommandLine(new Grades()).execute(args);
        System.exit(exitCode);
    }
}

@@ -57,16 +57,53 @@
 ndLine;%0A
+import picocli.CommandLine.ArgGroup;%0A
 import p
@@ -222,64 +222,10 @@
 l.Li
-nkedHashMap;%0Aimport java.util.List;%0Aimport java.util.Map
+st
 ;%0A%0A@
@@ -360,40 +360,24 @@
  // 
-unfortunately this does not work
+From picocli 4.3
 , se
@@ -424,18 +424,16 @@
 es/1027%0A
-//
     stat
@@ -456,18 +456,16 @@
 Grade %7B%0A
-//
         
@@ -502,18 +502,16 @@
 g name;%0A
-//
         
@@ -557,21 +557,101 @@
 de;%0A
-//    %7D%0A//%0A//
+%0A        public String toString() %7B%0A            return name + %22: %22 + grade;%0A        %7D%0A    %7D%0A%0A
     
@@ -702,18 +702,16 @@
 %221..*%22)%0A
-//
     List
@@ -733,24 +733,70 @@
 gradeList;%0A%0A
+    // workaround for picocli 4.2 and older%0A//
     @Paramet
@@ -812,16 +812,18 @@
  = %222%22,%0A
+//
         
@@ -883,16 +883,18 @@
 rade.%22,%0A
+//
         
@@ -953,16 +953,18 @@
 = true)%0A
+//
     List
@@ -1065,212 +1065,8 @@
 t);%0A
-        Map%3CString, BigDecimal%3E map = new LinkedHashMap%3C%3E();%0A        for (int i = 0; i %3C gradeList.size(); i += 2) %7B%0A            map.put(gradeList.get(i), new BigDecimal(gradeList.get(i + 1)));%0A        %7D%0A
     

update example