ArgsParser { public static ArgsParser parse(String[] args) { Options options = new Options(); Option source = new Option("s", "source", true, "the source graph file path on HDFS (Required)"); source.setRequired(true); Option target = new Option("t", "target", true, "the target graph file path on HDFS (Required)"); target.setRequired(true); Option output = new Option("o", "output", true, "the output folder path of MapReduce result on HDFS (Required)"); output.setRequired(true); Option help = new Option("h", "help", false, "show this help message and exit program"); options.addOption(source) .addOption(target) .addOption(output) .addOption(help); CommandLineParser parser = new BasicParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd = null; try { cmd = parser.parse(options, args); arguments.put(SOURCE, cmd.getOptionValue("s")); arguments.put(TARGET, cmd.getOptionValue("t")); arguments.put(OUTPUT, cmd.getOptionValue("o")); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("sub-Graph Isomorphism", options, true); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("sub-Graph Isomorphism", options, true); System.exit(0); } return new ArgsParser(); } private  ArgsParser(); static ArgsParser parse(String[] args); String getSourceGraphFilePath(); String getTargetGraphFilePath(); String getOutputFolderPath();  }
@Test public void parse() { ArrayList<String[]> args = new ArrayList<>(); args.add(new String[]{"-h"}); args.add(new String[]{"-s/home/source"}); args.add(new String[]{"-s", "/home/source", "-t", "/home/innofang/target", "-o", "/output"}); args.add(new String[]{"-s=/home/source", "-t=/home/innofang/target", "-o=/output"}); ArgsParser parser = ArgsParser.parse(args.get(2)); System.out.println(parser.getSourceGraphFilePath()); System.out.println(parser.getTargetGraphFilePath()); System.out.println(parser.getOutputFolderPath()); }