package io.digdag.cli;

import com.beust.jcommander.IParameterValidator;
import com.beust.jcommander.ParameterException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ParameterValidator implements IParameterValidator
{
    public void validate(String name, String value) throws ParameterException
    {
        if (!value.contains("=")) {
            throw new ParameterException("Parameter " + name + " expected a value of the form a=b but got:" + value);
        }
    }

    public static Map<String, String> toMap(List<String> list)
    {
        Map<String, String> map = new HashMap<>();
        list.forEach(value -> map.put(value.substring(0, value.indexOf("=")), value.substring(value.indexOf("=")+1)));
        return map;
    }
}

@@ -639,38 +639,125 @@
     
-list.forEach(value -%3E map.put(
+String key = null;%0A%0A        for (String value : list) %7B%0A            if (value.contains(%22=%22)) %7B%0A                key = 
 valu
@@ -790,17 +790,46 @@
 Of(%22=%22))
-,
+;%0A                String val =
  value.s
@@ -859,14 +859,241 @@
 %22=%22)
-+1)));
+ + 1);%0A                map.put(key, val);%0A            %7D%0A            else %7B%0A                String val = new StringBuilder(map.get(key)).append(%22,%22).append(value).toString();%0A                map.put(key, val);%0A            %7D%0A        %7D%0A
 %0A   
@@ -1115,10 +1115,9 @@
 ;%0A    %7D%0A
+
 %7D
-%0A

Fix string index out of bounds