Here you can find the source of getArgs(String[] args, String... singleArgs)
Parameter | Description |
---|---|
args | a parameter |
singleArgs | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static Map<String, String[]> getArgs(String[] args, String... singleArgs) throws Exception
//package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { /**//from www .java2 s. c o m * Get CLI arguments. * * @param args * @param singleArgs * @return * @throws Exception */ public static Map<String, String[]> getArgs(String[] args, String... singleArgs) throws Exception { Map<String, String[]> params = new HashMap<String, String[]>(); for (int i = 0; i < args.length; i++) { String inArg = args[i]; if (!inArg.startsWith("--")) { throw new Exception("Wrong argument syntax: " + inArg); } else { inArg = inArg.substring(2); } for (int j = 0; j < singleArgs.length; j++) { if (singleArgs[j].equals(inArg)) { params.put(inArg, new String[] {}); } } if (inArg.contains("=")) { String[] keyset = inArg.split("=", 2); if (keyset[1].startsWith("{") && keyset[1].endsWith("}")) { params.put( keyset[0], new String[] { keyset[1].substring(1, keyset[1].length() - 1) }); } else { params.put(keyset[0], keyset[1].split(",")); } } } return params; } }