@Test public void testParseCli9() { String[] args = new String[] {"--code", "cs", "--library", "trinity", "--name", "nmae", "--path", ".", "--out", "test"}; Map<String, Object> input = CliHelper.parseCLI(args); assertTrue(input.get("code").equals(CODE.C_SHARP)); assertTrue(input.get("library").equals(LIBRARY.TRINITY)); assertTrue(input.get("name").equals("nmae")); assertTrue(input.get("pathToOntologiesParam").equals(".")); assertTrue(!(boolean) input.get("skipCompile")); assertTrue(!(boolean) input.get("skipInverseRelations")); assertTrue(input.containsKey("out") && input.get("out").equals("test")); }
public static Map<String, Object> parseCLI(String[] args) { Options options = new Options(); Option outPath = Option.builder().argName("out").hasArg().longOpt("out") .desc(ResourceManager.getResource("outPathDesc")).build(); Option code = Option.builder().argName("code").hasArg().required() .desc(ResourceManager.getResource("codeDesc")).longOpt("code").build(); Option library = Option.builder().argName("library").hasArg().required().longOpt("library") .desc(ResourceManager.getResource("libraryDesc")).build(); Option name = Option.builder().argName("name").hasArg().required().longOpt("name") .desc(ResourceManager.getResource("nameDesc")).build(); Option pathToOntologies = Option.builder().argName("path").hasArg().required().longOpt("path") .desc(ResourceManager.getResource("pathToOntologiesDesc")).build(); Option version = Option.builder().argName("version").hasArg().longOpt("version") .desc(ResourceManager.getResource("versionDesc")).build(); Option skipInverseRelations = Option.builder().argName("skipInverseRelations").hasArg(false) .longOpt("skipInverseRelations") .desc(ResourceManager.getResource("skipInverseRelationsDesc")).build(); Option skipCompilation = Option.builder().argName("skipCompile").hasArg(false) .longOpt("skipCompile").desc(ResourceManager.getResource("skipCompileDesc")).build(); options.addOption(code); options.addOption(skipInverseRelations); options.addOption(outPath); options.addOption(library); options.addOption(name); options.addOption(pathToOntologies); options.addOption(version); options.addOption("preserve", false, "a parameter if set to true will preserve the namespace of the ontology during code generation"); options.addOption("partial", false, "a parameter if set to true will generate C# code where all classes are partial"); options.addOption("skipCleaning", false, "Skip Directory Cleaning Phase"); options.addOption(skipCompilation); defaultParser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); try { inputCmdParameters.clear(); CommandLine line = defaultParser.parse(options, args); if (line.hasOption("code")) { inputCmdParameters.put("code", CODE.fromString(line.getOptionValue("code"))); } if (line.hasOption("out")) { inputCmdParameters.put("out", line.getOptionValue("out")); } if (line.hasOption("library")) { inputCmdParameters.put("library", LIBRARY.fromString(line.getOptionValue("library"))); } if (line.hasOption("path")) { inputCmdParameters.put("pathToOntologiesParam", line.getOptionValue("path")); } if (line.hasOption("name")) { inputCmdParameters.put("name", line.getOptionValue("name")); } if (line.hasOption("version")) { inputCmdParameters.put("ontVersion", Optional.of(line.getOptionValue("version")).get()); } if (line.hasOption("preserve")) { inputCmdParameters.put("preserve", true); } if (line.hasOption("skipCleaning")) { inputCmdParameters.put("skipCleaning", true); } if (line.hasOption("partial")) { inputCmdParameters.put("partial", true); } if (line.hasOption("help")) { formatter.printHelp("help", options); } if (line.hasOption("skipInverseRelations")) { inputCmdParameters.put("skipInverseRelations", true); } else { inputCmdParameters.put("skipInverseRelations", false); } inputCmdParameters.put("skipCompile", line.hasOption("skipCompile")); } catch (ParseException exp) { System.out.println("Missing argument:" + exp.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } return inputCmdParameters; }
CliHelper { public static Map<String, Object> parseCLI(String[] args) { Options options = new Options(); Option outPath = Option.builder().argName("out").hasArg().longOpt("out") .desc(ResourceManager.getResource("outPathDesc")).build(); Option code = Option.builder().argName("code").hasArg().required() .desc(ResourceManager.getResource("codeDesc")).longOpt("code").build(); Option library = Option.builder().argName("library").hasArg().required().longOpt("library") .desc(ResourceManager.getResource("libraryDesc")).build(); Option name = Option.builder().argName("name").hasArg().required().longOpt("name") .desc(ResourceManager.getResource("nameDesc")).build(); Option pathToOntologies = Option.builder().argName("path").hasArg().required().longOpt("path") .desc(ResourceManager.getResource("pathToOntologiesDesc")).build(); Option version = Option.builder().argName("version").hasArg().longOpt("version") .desc(ResourceManager.getResource("versionDesc")).build(); Option skipInverseRelations = Option.builder().argName("skipInverseRelations").hasArg(false) .longOpt("skipInverseRelations") .desc(ResourceManager.getResource("skipInverseRelationsDesc")).build(); Option skipCompilation = Option.builder().argName("skipCompile").hasArg(false) .longOpt("skipCompile").desc(ResourceManager.getResource("skipCompileDesc")).build(); options.addOption(code); options.addOption(skipInverseRelations); options.addOption(outPath); options.addOption(library); options.addOption(name); options.addOption(pathToOntologies); options.addOption(version); options.addOption("preserve", false, "a parameter if set to true will preserve the namespace of the ontology during code generation"); options.addOption("partial", false, "a parameter if set to true will generate C# code where all classes are partial"); options.addOption("skipCleaning", false, "Skip Directory Cleaning Phase"); options.addOption(skipCompilation); defaultParser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); try { inputCmdParameters.clear(); CommandLine line = defaultParser.parse(options, args); if (line.hasOption("code")) { inputCmdParameters.put("code", CODE.fromString(line.getOptionValue("code"))); } if (line.hasOption("out")) { inputCmdParameters.put("out", line.getOptionValue("out")); } if (line.hasOption("library")) { inputCmdParameters.put("library", LIBRARY.fromString(line.getOptionValue("library"))); } if (line.hasOption("path")) { inputCmdParameters.put("pathToOntologiesParam", line.getOptionValue("path")); } if (line.hasOption("name")) { inputCmdParameters.put("name", line.getOptionValue("name")); } if (line.hasOption("version")) { inputCmdParameters.put("ontVersion", Optional.of(line.getOptionValue("version")).get()); } if (line.hasOption("preserve")) { inputCmdParameters.put("preserve", true); } if (line.hasOption("skipCleaning")) { inputCmdParameters.put("skipCleaning", true); } if (line.hasOption("partial")) { inputCmdParameters.put("partial", true); } if (line.hasOption("help")) { formatter.printHelp("help", options); } if (line.hasOption("skipInverseRelations")) { inputCmdParameters.put("skipInverseRelations", true); } else { inputCmdParameters.put("skipInverseRelations", false); } inputCmdParameters.put("skipCompile", line.hasOption("skipCompile")); } catch (ParseException exp) { System.out.println("Missing argument:" + exp.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } return inputCmdParameters; } }
CliHelper { public static Map<String, Object> parseCLI(String[] args) { Options options = new Options(); Option outPath = Option.builder().argName("out").hasArg().longOpt("out") .desc(ResourceManager.getResource("outPathDesc")).build(); Option code = Option.builder().argName("code").hasArg().required() .desc(ResourceManager.getResource("codeDesc")).longOpt("code").build(); Option library = Option.builder().argName("library").hasArg().required().longOpt("library") .desc(ResourceManager.getResource("libraryDesc")).build(); Option name = Option.builder().argName("name").hasArg().required().longOpt("name") .desc(ResourceManager.getResource("nameDesc")).build(); Option pathToOntologies = Option.builder().argName("path").hasArg().required().longOpt("path") .desc(ResourceManager.getResource("pathToOntologiesDesc")).build(); Option version = Option.builder().argName("version").hasArg().longOpt("version") .desc(ResourceManager.getResource("versionDesc")).build(); Option skipInverseRelations = Option.builder().argName("skipInverseRelations").hasArg(false) .longOpt("skipInverseRelations") .desc(ResourceManager.getResource("skipInverseRelationsDesc")).build(); Option skipCompilation = Option.builder().argName("skipCompile").hasArg(false) .longOpt("skipCompile").desc(ResourceManager.getResource("skipCompileDesc")).build(); options.addOption(code); options.addOption(skipInverseRelations); options.addOption(outPath); options.addOption(library); options.addOption(name); options.addOption(pathToOntologies); options.addOption(version); options.addOption("preserve", false, "a parameter if set to true will preserve the namespace of the ontology during code generation"); options.addOption("partial", false, "a parameter if set to true will generate C# code where all classes are partial"); options.addOption("skipCleaning", false, "Skip Directory Cleaning Phase"); options.addOption(skipCompilation); defaultParser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); try { inputCmdParameters.clear(); CommandLine line = defaultParser.parse(options, args); if (line.hasOption("code")) { inputCmdParameters.put("code", CODE.fromString(line.getOptionValue("code"))); } if (line.hasOption("out")) { inputCmdParameters.put("out", line.getOptionValue("out")); } if (line.hasOption("library")) { inputCmdParameters.put("library", LIBRARY.fromString(line.getOptionValue("library"))); } if (line.hasOption("path")) { inputCmdParameters.put("pathToOntologiesParam", line.getOptionValue("path")); } if (line.hasOption("name")) { inputCmdParameters.put("name", line.getOptionValue("name")); } if (line.hasOption("version")) { inputCmdParameters.put("ontVersion", Optional.of(line.getOptionValue("version")).get()); } if (line.hasOption("preserve")) { inputCmdParameters.put("preserve", true); } if (line.hasOption("skipCleaning")) { inputCmdParameters.put("skipCleaning", true); } if (line.hasOption("partial")) { inputCmdParameters.put("partial", true); } if (line.hasOption("help")) { formatter.printHelp("help", options); } if (line.hasOption("skipInverseRelations")) { inputCmdParameters.put("skipInverseRelations", true); } else { inputCmdParameters.put("skipInverseRelations", false); } inputCmdParameters.put("skipCompile", line.hasOption("skipCompile")); } catch (ParseException exp) { System.out.println("Missing argument:" + exp.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } return inputCmdParameters; }  }
CliHelper { public static Map<String, Object> parseCLI(String[] args) { Options options = new Options(); Option outPath = Option.builder().argName("out").hasArg().longOpt("out") .desc(ResourceManager.getResource("outPathDesc")).build(); Option code = Option.builder().argName("code").hasArg().required() .desc(ResourceManager.getResource("codeDesc")).longOpt("code").build(); Option library = Option.builder().argName("library").hasArg().required().longOpt("library") .desc(ResourceManager.getResource("libraryDesc")).build(); Option name = Option.builder().argName("name").hasArg().required().longOpt("name") .desc(ResourceManager.getResource("nameDesc")).build(); Option pathToOntologies = Option.builder().argName("path").hasArg().required().longOpt("path") .desc(ResourceManager.getResource("pathToOntologiesDesc")).build(); Option version = Option.builder().argName("version").hasArg().longOpt("version") .desc(ResourceManager.getResource("versionDesc")).build(); Option skipInverseRelations = Option.builder().argName("skipInverseRelations").hasArg(false) .longOpt("skipInverseRelations") .desc(ResourceManager.getResource("skipInverseRelationsDesc")).build(); Option skipCompilation = Option.builder().argName("skipCompile").hasArg(false) .longOpt("skipCompile").desc(ResourceManager.getResource("skipCompileDesc")).build(); options.addOption(code); options.addOption(skipInverseRelations); options.addOption(outPath); options.addOption(library); options.addOption(name); options.addOption(pathToOntologies); options.addOption(version); options.addOption("preserve", false, "a parameter if set to true will preserve the namespace of the ontology during code generation"); options.addOption("partial", false, "a parameter if set to true will generate C# code where all classes are partial"); options.addOption("skipCleaning", false, "Skip Directory Cleaning Phase"); options.addOption(skipCompilation); defaultParser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); try { inputCmdParameters.clear(); CommandLine line = defaultParser.parse(options, args); if (line.hasOption("code")) { inputCmdParameters.put("code", CODE.fromString(line.getOptionValue("code"))); } if (line.hasOption("out")) { inputCmdParameters.put("out", line.getOptionValue("out")); } if (line.hasOption("library")) { inputCmdParameters.put("library", LIBRARY.fromString(line.getOptionValue("library"))); } if (line.hasOption("path")) { inputCmdParameters.put("pathToOntologiesParam", line.getOptionValue("path")); } if (line.hasOption("name")) { inputCmdParameters.put("name", line.getOptionValue("name")); } if (line.hasOption("version")) { inputCmdParameters.put("ontVersion", Optional.of(line.getOptionValue("version")).get()); } if (line.hasOption("preserve")) { inputCmdParameters.put("preserve", true); } if (line.hasOption("skipCleaning")) { inputCmdParameters.put("skipCleaning", true); } if (line.hasOption("partial")) { inputCmdParameters.put("partial", true); } if (line.hasOption("help")) { formatter.printHelp("help", options); } if (line.hasOption("skipInverseRelations")) { inputCmdParameters.put("skipInverseRelations", true); } else { inputCmdParameters.put("skipInverseRelations", false); } inputCmdParameters.put("skipCompile", line.hasOption("skipCompile")); } catch (ParseException exp) { System.out.println("Missing argument:" + exp.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } return inputCmdParameters; }  static Map<String, Object> parseCLI(String[] args); }
CliHelper { public static Map<String, Object> parseCLI(String[] args) { Options options = new Options(); Option outPath = Option.builder().argName("out").hasArg().longOpt("out") .desc(ResourceManager.getResource("outPathDesc")).build(); Option code = Option.builder().argName("code").hasArg().required() .desc(ResourceManager.getResource("codeDesc")).longOpt("code").build(); Option library = Option.builder().argName("library").hasArg().required().longOpt("library") .desc(ResourceManager.getResource("libraryDesc")).build(); Option name = Option.builder().argName("name").hasArg().required().longOpt("name") .desc(ResourceManager.getResource("nameDesc")).build(); Option pathToOntologies = Option.builder().argName("path").hasArg().required().longOpt("path") .desc(ResourceManager.getResource("pathToOntologiesDesc")).build(); Option version = Option.builder().argName("version").hasArg().longOpt("version") .desc(ResourceManager.getResource("versionDesc")).build(); Option skipInverseRelations = Option.builder().argName("skipInverseRelations").hasArg(false) .longOpt("skipInverseRelations") .desc(ResourceManager.getResource("skipInverseRelationsDesc")).build(); Option skipCompilation = Option.builder().argName("skipCompile").hasArg(false) .longOpt("skipCompile").desc(ResourceManager.getResource("skipCompileDesc")).build(); options.addOption(code); options.addOption(skipInverseRelations); options.addOption(outPath); options.addOption(library); options.addOption(name); options.addOption(pathToOntologies); options.addOption(version); options.addOption("preserve", false, "a parameter if set to true will preserve the namespace of the ontology during code generation"); options.addOption("partial", false, "a parameter if set to true will generate C# code where all classes are partial"); options.addOption("skipCleaning", false, "Skip Directory Cleaning Phase"); options.addOption(skipCompilation); defaultParser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); try { inputCmdParameters.clear(); CommandLine line = defaultParser.parse(options, args); if (line.hasOption("code")) { inputCmdParameters.put("code", CODE.fromString(line.getOptionValue("code"))); } if (line.hasOption("out")) { inputCmdParameters.put("out", line.getOptionValue("out")); } if (line.hasOption("library")) { inputCmdParameters.put("library", LIBRARY.fromString(line.getOptionValue("library"))); } if (line.hasOption("path")) { inputCmdParameters.put("pathToOntologiesParam", line.getOptionValue("path")); } if (line.hasOption("name")) { inputCmdParameters.put("name", line.getOptionValue("name")); } if (line.hasOption("version")) { inputCmdParameters.put("ontVersion", Optional.of(line.getOptionValue("version")).get()); } if (line.hasOption("preserve")) { inputCmdParameters.put("preserve", true); } if (line.hasOption("skipCleaning")) { inputCmdParameters.put("skipCleaning", true); } if (line.hasOption("partial")) { inputCmdParameters.put("partial", true); } if (line.hasOption("help")) { formatter.printHelp("help", options); } if (line.hasOption("skipInverseRelations")) { inputCmdParameters.put("skipInverseRelations", true); } else { inputCmdParameters.put("skipInverseRelations", false); } inputCmdParameters.put("skipCompile", line.hasOption("skipCompile")); } catch (ParseException exp) { System.out.println("Missing argument:" + exp.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); formatter.printHelp("help", options); inputCmdParameters.clear(); return null; } return inputCmdParameters; }  static Map<String, Object> parseCLI(String[] args);  }