ArgsUtil { public static String[] extractArguments(Object bean) throws Exception { List<Getter<?>> arguments = null; arguments = parse(bean); List<String> args = new ArrayList<String>(); for (Getter<?> optionHandler : arguments) { List<IndependentPair<String, Class<?>>> values = optionHandler.getStringValues(); for (IndependentPair<String, Class<?>> object : values) { if(object.secondObject() == Boolean.class){ if(object.firstObject() == null){ continue; } else{ args.add(optionHandler.getOptionName()); } } else{ args.add(optionHandler.getOptionName()); args.add(object.firstObject()); } } } return args.toArray(new String[args.size()]); } private  ArgsUtil(); static String[] extractArguments(Object bean);  }
@Test public void testArgs() throws Exception { final Arguments args = new Arguments(); args.list.add("wang"); args.list.add("bang"); args.statusType = Opt.SECOND; String[] asArgArray = ArgsUtil.extractArguments(args); System.out.println(Arrays.toString(asArgArray)); CmdLineParser parser = new CmdLineParser(args); parser.parseArgument(asArgArray); args.outputModeOption = ProxyOption.SECOND; args.outputModeOptionOp = (ProxyOptionDetails) args.outputModeOption.getOptions(); args.string = 2; args.bool = true; asArgArray = ArgsUtil.extractArguments(args); parser = new CmdLineParser(args); parser.parseArgument(asArgArray); System.out.println(Arrays.toString(asArgArray)); }