All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.jbang.cli.KeyValueConsumer Maven / Gradle / Ivy

There is a newer version: 0.121.0
Show newest version
package dev.jbang.cli;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import picocli.CommandLine;

public class KeyValueConsumer implements CommandLine.IParameterConsumer {

	Pattern p = Pattern.compile("(\\S*?)(=(\\S+))?");

	@Override
	public void consumeParameters(Stack args, CommandLine.Model.ArgSpec argSpec,
			CommandLine.Model.CommandSpec commandSpec) {
		String arg = args.pop();
		Matcher m = p.matcher(arg);
		if (m.matches()) {
			Map kv = argSpec.getValue();

			if (kv == null) {
				kv = new LinkedHashMap<>();
			}

			kv.put(m.group(1), m.group(3));

			argSpec.setValue(kv);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy