class CommandUtils {

	public static Parameters parse(String[] inArgs) {
		ParametersImpl params = new ParametersImpl();
		
		String[] args = preParse(inArgs);
		
		for (int i = 1; i < args.length; i++) {
			String arg = args[i];
			if (arg.startsWith(ARG_PREFIX) && arg.length() > ARG_PREFIX_LEGTH) {
				String param;
				String value;
				int sepIdx = arg.indexOf(ARG_VALUE_SEPARATOR);

				if (sepIdx >= 0) {
					param = arg.substring(ARG_PREFIX_LEGTH, sepIdx);
					value = arg.substring(sepIdx + 1);
				} else {
					param = arg.substring(ARG_PREFIX_LEGTH);
					value = null;
				}
				
				params.addParameter(param);
				if (value != null) {
					addParameterValues(params, param, value);
				}
				
				int j;
				for (j = i + 1; j < args.length; ++j) {
					String argn = args[j];
					if (argn.startsWith(ARG_PREFIX)) {
						break;
					}
					addParameterValues(params, param, argn);
				}
				i = j - 1;
			}
		}
		return params;
	}

}