List of usage examples for org.apache.commons.cli DefaultParser DefaultParser
DefaultParser
From source file:com.blackducksoftware.tools.vuln_collector.VCRunner.java
public static void main(String[] args) throws Exception { System.out.println(TITLE);//from w ww .j a v a 2 s . co m CommandLineParser parser = new DefaultParser(); options.addOption("h", "help", false, "show help."); Option projectNameOption = new Option("projectName", true, "Name of Project (optional)"); projectNameOption.setRequired(false); options.addOption(projectNameOption); Option configFileOption = new Option("config", true, "Location of configuration file (required)"); configFileOption.setRequired(true); options.addOption(configFileOption); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) help(); String[] projectNameList = null; File configFile = null; if (cmd.hasOption(VCConstants.CL_PROJECT_NAME)) { String projectName = cmd.getOptionValue(VCConstants.CL_PROJECT_NAME); log.info("Project name: " + projectName); // Could be a single project or comma delim projectNameList = VCProcessor.getProjectList(projectName); } // Config File if (cmd.hasOption(VCConstants.CL_CONFIG)) { String configFilePath = cmd.getOptionValue(VCConstants.CL_CONFIG); log.info("Config file location: " + configFilePath); configFile = new File(configFilePath); if (!configFile.exists()) { log.error("Configuration file does not exist at location: " + configFile); System.exit(-1); } } else { log.error("Must specify configuration file!"); help(); } VCProcessor processor = new VCProcessor(configFile.toString(), projectNameList); processor.processReport(); } catch (ParseException e) { log.error("Error parsing: " + e.getMessage()); help(); } catch (Exception e) { log.error("General error: " + e.getMessage()); } }
From source file:com.twitter.bazel.checkstyle.PythonCheckstyle.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new DefaultParser(); // create the Options Options options = new Options(); options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file") .desc("bazel extra action protobuf file").build()); options.addOption(Option.builder("p").required(true).hasArg().longOpt("pylint_file") .desc("Executable pylint file to invoke").build()); try {//from ww w .ja v a2 s.c o m // parse the command line arguments CommandLine line = parser.parse(options, args); String extraActionFile = line.getOptionValue("f"); String pylintFile = line.getOptionValue("p"); Collection<String> sourceFiles = getSourceFiles(extraActionFile); if (sourceFiles.size() == 0) { LOG.info("No python files found by checkstyle"); return; } LOG.info(sourceFiles.size() + " python files found by checkstyle"); // Create and run the command List<String> commandBuilder = new ArrayList<>(); commandBuilder.add(pylintFile); commandBuilder.addAll(sourceFiles); runLinter(commandBuilder); } catch (ParseException exp) { LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage())); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java " + CLASSNAME, options); } }
From source file:com.twitter.bazel.checkstyle.CppCheckstyle.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new DefaultParser(); // create the Options Options options = new Options(); options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file") .desc("bazel extra action protobuf file").build()); options.addOption(Option.builder("c").required(true).hasArg().longOpt("cpplint_file") .desc("Executable cpplint file to invoke").build()); try {//from w w w . j ava 2 s.com // parse the command line arguments CommandLine line = parser.parse(options, args); String extraActionFile = line.getOptionValue("f"); String cpplintFile = line.getOptionValue("c"); Collection<String> sourceFiles = getSourceFiles(extraActionFile); if (sourceFiles.size() == 0) { LOG.fine("No cpp files found by checkstyle"); return; } LOG.fine(sourceFiles.size() + " cpp files found by checkstyle"); // Create and run the command List<String> commandBuilder = new ArrayList<>(); commandBuilder.add(cpplintFile); commandBuilder.add("--linelength=100"); // TODO: https://github.com/twitter/heron/issues/466, // Remove "runtime/references" when we fix all non-const references in our codebase. // TODO: https://github.com/twitter/heron/issues/467, // Remove "runtime/threadsafe_fn" when we fix all non-threadsafe libc functions commandBuilder.add("--filter=-build/header_guard,-runtime/references,-runtime/threadsafe_fn"); commandBuilder.addAll(sourceFiles); runLinter(commandBuilder); } catch (ParseException exp) { LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage())); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java " + CLASSNAME, options); } }
From source file:dyco4j.instrumentation.entry.CLI.java
public static void main(final String[] args) throws IOException { final Options _options = new Options(); _options.addOption(Option.builder().longOpt(IN_FOLDER_OPTION).required().hasArg() .desc("Folder containing the classes (as descendants) to be instrumented.").build()); _options.addOption(Option.builder().longOpt(OUT_FOLDER_OPTION).required().hasArg() .desc("Folder containing the classes (as descendants) with instrumentation.").build()); final String _msg = MessageFormat.format("Regex identifying the methods to be instrumented. Default: {0}.", METHOD_NAME_REGEX);/*from w ww .j a v a2 s. com*/ _options.addOption(Option.builder().longOpt(METHOD_NAME_REGEX_OPTION).hasArg(true).desc(_msg).build()); _options.addOption(Option.builder().longOpt(ONLY_ANNOTATED_TESTS_OPTION).hasArg(false) .desc("Instrument only tests identified by annotations.").build()); try { processCommandLine(new DefaultParser().parse(_options, args)); } catch (final ParseException _ex) { new HelpFormatter().printHelp(CLI.class.getName(), _options); } }
From source file:de.peran.DependencyReadingStarter.java
public static void main(final String[] args) throws ParseException, FileNotFoundException { final Options options = OptionConstants.createOptions(OptionConstants.FOLDER, OptionConstants.STARTVERSION, OptionConstants.ENDVERSION, OptionConstants.OUT); final CommandLineParser parser = new DefaultParser(); final CommandLine line = parser.parse(options, args); final File projectFolder = new File(line.getOptionValue(OptionConstants.FOLDER.getName())); final File dependencyFile; if (line.hasOption(OptionConstants.OUT.getName())) { dependencyFile = new File(line.getOptionValue(OptionConstants.OUT.getName())); } else {//from w ww . j a v a 2 s.c om dependencyFile = new File("dependencies.xml"); } File outputFile = projectFolder.getParentFile(); if (outputFile.isDirectory()) { outputFile = new File(projectFolder.getParentFile(), "ausgabe.txt"); } LOG.debug("Lese {}", projectFolder.getAbsolutePath()); final VersionControlSystem vcs = VersionControlSystem.getVersionControlSystem(projectFolder); System.setOut(new PrintStream(outputFile)); // System.setErr(new PrintStream(outputFile)); final DependencyReader reader; if (vcs.equals(VersionControlSystem.SVN)) { final String url = SVNUtils.getInstance().getWCURL(projectFolder); final List<SVNLogEntry> entries = getSVNCommits(line, url); LOG.debug("SVN commits: " + entries.stream().map(entry -> entry.getRevision()).collect(Collectors.toList())); reader = new DependencyReader(projectFolder, url, dependencyFile, entries); } else if (vcs.equals(VersionControlSystem.GIT)) { final List<GitCommit> commits = getGitCommits(line, projectFolder); reader = new DependencyReader(projectFolder, dependencyFile, commits); LOG.debug("Reader initalized"); } else { throw new RuntimeException("Unknown version control system"); } reader.readDependencies(); }
From source file:cz.muni.fi.crocs.EduHoc.Main.java
/** * @param args the command line arguments *///from w w w . j a v a 2s.co m public static void main(String[] args) { System.out.println("JeeTool \n"); Options options = OptionsMain.createOptions(); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException ex) { System.err.println("cannot parse parameters"); OptionsMain.printHelp(options); System.err.println(ex.toString()); return; } boolean silent = cmd.hasOption("s"); boolean verbose = cmd.hasOption("v"); if (!silent) { System.out.println(ANSI_GREEN + "EduHoc home is: " + System.getenv("EDU_HOC_HOME") + "\n" + ANSI_RESET); } //help if (cmd.hasOption("h")) { OptionsMain.printHelp(options); return; } String filepath; //path to config list of nodes if (cmd.hasOption("a")) { filepath = cmd.getOptionValue("a"); } else { filepath = System.getenv("EDU_HOC_HOME") + "/config/motePaths.txt"; } //create motelist MoteList moteList = new MoteList(filepath); if (verbose) { moteList.setVerbose(); } if (silent) { moteList.setSilent(); } if (verbose) { System.out.println("reading motelist from file " + filepath); } if (cmd.hasOption("i")) { List<Integer> ids = new ArrayList<Integer>(); String arg = cmd.getOptionValue("i"); String[] IdArgs = arg.split(","); for (String s : IdArgs) { if (s.contains("-")) { int start = Integer.parseInt(s.substring(0, s.indexOf("-"))); int end = Integer.parseInt(s.substring(s.indexOf("-") + 1, s.length())); for (int i = start; i <= end; i++) { ids.add(i); } } else { ids.add(Integer.parseInt(s)); } } moteList.setIds(ids); } moteList.readFile(); if (cmd.hasOption("d")) { //only detect nodes return; } //if make if (cmd.hasOption("m") || cmd.hasOption("c") || cmd.hasOption("u")) { UploadMain upload = new UploadMain(moteList, cmd); upload.runMake(); } //if execute command if (cmd.hasOption("E")) { try { ExecuteShellCommand com = new ExecuteShellCommand(); if (verbose) { System.out.println("Executing shell command " + cmd.getOptionValue("E")); } com.executeCommand(cmd.getOptionValue("E")); } catch (IOException ex) { System.err.println("Execute command " + cmd.getOptionValue("E") + " failed"); } } //if serial if (cmd.hasOption("l") || cmd.hasOption("w")) { SerialMain serial = new SerialMain(cmd, moteList); if (silent) { serial.setSilent(); } if (verbose) { serial.setVerbose(); } serial.startSerial(); } }
From source file:com.blackducksoftware.tools.nrt.NoticeReportTool.java
/** * @param args//from w ww. j ava 2s . c o m * @throws Exception */ public static void main(String[] args) throws Exception { System.out.println("Notice Report Tool for Black Duck Suite"); CommandLineParser parser = new DefaultParser(); options.addOption("h", "help", false, "show help."); Option applicationOption = new Option(NRTConstants.CL_APPLICATION_TYPE, true, "Application type [PROTEX|CODECENTER] (required)"); applicationOption.setRequired(true); options.addOption(applicationOption); Option configFileOption = new Option(NRTConstants.CL_CONFIG_FILE, true, "Location of configuration file (required)"); configFileOption.setRequired(true); options.addOption(configFileOption); Option projectNameOption = new Option(NRTConstants.CL_PROJECT_NAME, true, "Name of Protex project (will override configuration file)"); projectNameOption.setRequired(false); options.addOption(projectNameOption); File configFile = null; APPLICATION applicationType = null; String projectName = null; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { help(); } // Config File if (cmd.hasOption(NRTConstants.CL_CONFIG_FILE)) { String configFilePath = cmd.getOptionValue(NRTConstants.CL_CONFIG_FILE); log.info("Config file location: " + configFilePath); configFile = new File(configFilePath); if (!configFile.exists()) { log.error("Configuration file does not exist at location: " + configFile); System.exit(-1); } } else { log.error("Must specify configuration file!"); help(); } if (cmd.hasOption(NRTConstants.CL_APPLICATION_TYPE)) { String bdsApplicationType = cmd.getOptionValue(NRTConstants.CL_APPLICATION_TYPE); try { applicationType = APPLICATION.valueOf(bdsApplicationType); } catch (IllegalArgumentException e) { log.error("No such application type recognized: " + bdsApplicationType); help(); } } else { help(); } if (cmd.hasOption(NRTConstants.CL_PROJECT_NAME)) { projectName = cmd.getOptionValue(NRTConstants.CL_PROJECT_NAME); log.info("User specified project name: " + projectName); } NoticeReportProcessor processor = new NoticeReportProcessor(configFile.getAbsolutePath(), applicationType, projectName); try { processor.connect(); } catch (Exception e) { log.error("Connection problems: " + e.getMessage()); throw new Exception(e); } processor.processReport(); } catch (Exception e) { log.error("Error: " + e.getMessage()); help(); } }
From source file:io.wcm.devops.conga.tooling.cli.CongaCli.java
/** * CLI entry point/* w w w . j a v a2s. c om*/ * @param args Command line arguments * @throws Exception */ //CHECKSTYLE:OFF public static void main(String[] args) throws Exception { //CHECKSTYLE:ON CommandLine commandLine = new DefaultParser().parse(CLI_OPTIONS, args); if (commandLine.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(150); formatter.printHelp("java -cp io.wcm.devops.conga.tooling.cli-<version>.jar " + "io.wcm.devops.conga.tooling.cli.CongaCli <arguments>", CLI_OPTIONS); return; } String templateDir = commandLine.getOptionValue("templateDir", "templates"); String roleDir = commandLine.getOptionValue("roleDir", "roles"); String environmentDir = commandLine.getOptionValue("environmentDir", "environments"); String targetDir = commandLine.getOptionValue("target", "target"); String[] environments = StringUtils.split(commandLine.getOptionValue("environments", null), ","); ResourceLoader resourceLoader = new ResourceLoader(); List<ResourceCollection> roleDirs = ImmutableList .of(resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + roleDir)); List<ResourceCollection> templateDirs = ImmutableList .of(resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + templateDir)); List<ResourceCollection> environmentDirs = ImmutableList .of(resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + environmentDir)); File targetDirecotry = new File(targetDir); Generator generator = new Generator(roleDirs, templateDirs, environmentDirs, targetDirecotry); generator.setDeleteBeforeGenerate(true); generator.generate(environments); }
From source file:com.xafero.vee.cmd.MainApp.java
public static void main(String[] args) { // Define options Option help = new Option("?", "help", false, "print this message"); Option version = new Option("v", "version", false, "print the version information and exit"); Option eval = Option.builder("e").desc("evaluate script").argName("file").longOpt("eval").hasArg().build(); Option list = new Option("l", "list", false, "print all available languages"); // Collect them Options options = new Options(); options.addOption(help);/* w w w . jav a2 s . c o m*/ options.addOption(version); options.addOption(eval); options.addOption(list); // If nothing given, nothing will happen if (args == null || args.length < 1) { printHelp(options); return; } // Parse command line try { CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); // Work on it process(line, options); } catch (Throwable e) { System.err.printf("Error occurred: %n " + e.getMessage()); } }
From source file:com.canyapan.randompasswordgenerator.cli.Main.java
public static void main(String[] args) { Options options = new Options(); options.addOption("h", false, "prints help"); options.addOption("def", false, "generates 8 character password with default options"); options.addOption("p", true, "password length (default 8)"); options.addOption("l", false, "include lower case characters"); options.addOption("u", false, "include upper case characters"); options.addOption("d", false, "include digits"); options.addOption("s", false, "include symbols"); options.addOption("lc", true, "minimum lower case character count (default 0)"); options.addOption("uc", true, "minimum upper case character count (default 0)"); options.addOption("dc", true, "minimum digit count (default 0)"); options.addOption("sc", true, "minimum symbol count (default 0)"); options.addOption("a", false, "avoid ambiguous characters"); options.addOption("f", false, "force every character type"); options.addOption("c", false, "continuous password generation"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;//from w w w . j av a2 s . c o m boolean printHelp = false; try { cmd = parser.parse(options, args); } catch (ParseException e) { printHelp = true; } if (printHelp || args.length == 0 || cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "java -jar RandomPasswordGenerator.jar [-p <arg>] [-l] [-u] [-s] [-d] [-dc <arg>] [-a] [-f]", options); return; } RandomPasswordGenerator rpg = new RandomPasswordGenerator(); if (cmd.hasOption("def")) { rpg.withDefault().withPasswordLength(Integer.parseInt(cmd.getOptionValue("p", "8"))); } else { rpg.withPasswordLength(Integer.parseInt(cmd.getOptionValue("p", "8"))) .withLowerCaseCharacters(cmd.hasOption("l")).withUpperCaseCharacters(cmd.hasOption("u")) .withDigits(cmd.hasOption("d")).withSymbols(cmd.hasOption("s")) .withAvoidAmbiguousCharacters(cmd.hasOption("a")) .withForceEveryCharacterType(cmd.hasOption("f")); if (cmd.hasOption("lc")) { rpg.withMinLowerCaseCharacterCount(Integer.parseInt(cmd.getOptionValue("lc", "0"))); } if (cmd.hasOption("uc")) { rpg.withMinUpperCaseCharacterCount(Integer.parseInt(cmd.getOptionValue("uc", "0"))); } if (cmd.hasOption("dc")) { rpg.withMinDigitCount(Integer.parseInt(cmd.getOptionValue("dc", "0"))); } if (cmd.hasOption("sc")) { rpg.withMinSymbolCount(Integer.parseInt(cmd.getOptionValue("sc", "0"))); } } Scanner scanner = new Scanner(System.in); try { do { final String password = rpg.generate(); final PasswordMeter.Result result = PasswordMeter.check(password); System.out.printf("%s%nScore: %s%%%nComplexity: %s%n%n", password, result.getScore(), result.getComplexity()); if (cmd.hasOption("c")) { System.out.print("Another? y/N: "); } } while (cmd.hasOption("c") && scanner.nextLine().matches("^(?i:y(?:es)?)$")); } catch (RandomPasswordGeneratorException e) { System.err.println(e.getMessage()); } catch (PasswordMeterException e) { System.err.println(e.getMessage()); } }