List of usage examples for org.apache.commons.cli UnrecognizedOptionException getLocalizedMessage
public String getLocalizedMessage()
From source file:net.timbusproject.extractors.debiansoftwareextractor.CLI.java
public void parse(String... args) throws ParseException { try {/*from w w w.j a v a 2 s. co m*/ cmd = new PosixParser().parse(options, args); } catch (UnrecognizedOptionException e) { log.error(e.getLocalizedMessage()); throw e; } catch (MissingOptionException e) { log.error(e.getLocalizedMessage()); throw e; } catch (MissingArgumentException e) { log.error(e.getLocalizedMessage()); throw e; } catch (AlreadySelectedException e) { log.error(e.getLocalizedMessage()); throw e; } catch (ParseException e) { log.error(e.getLocalizedMessage()); e.printStackTrace(); throw e; } }
From source file:nl.cyso.vcloud.client.config.Configuration.java
public static CommandLine parseCli(ModeType mode, String[] args) { CommandLine cli = null;/*from ww w. ja va2 s. co m*/ Options opt = ConfigModes.getMode(mode); try { cli = new IgnorePosixParser(true).parse(opt, args); } catch (MissingArgumentException me) { Formatter.usageError(me.getLocalizedMessage(), mode); System.exit(-1); } catch (MissingOptionException mo) { Formatter.usageError(mo.getLocalizedMessage(), mode); System.exit(-1); } catch (AlreadySelectedException ase) { Formatter.usageError(ase.getLocalizedMessage(), mode); } catch (UnrecognizedOptionException uoe) { Formatter.usageError(uoe.getLocalizedMessage(), mode); } catch (ParseException e) { Formatter.printStackTrace(e); System.exit(-1); } return cli; }
From source file:nl.cyso.vsphere.client.config.Configuration.java
public static CommandLine parseCli(String mode, String[] args, boolean dieOnFailure) throws Exception { CommandLine cli = null;/*from w ww. j av a2 s. c om*/ Options opt = ConfigModes.getMode(mode); Throwable die = null; try { cli = new IgnorePosixParser(true).parse(opt, args); } catch (MissingArgumentException me) { Formatter.usageError(me.getLocalizedMessage(), mode, false); die = me; } catch (MissingOptionException mo) { Formatter.usageError(mo.getLocalizedMessage(), mode, false); die = mo; } catch (AlreadySelectedException ase) { Formatter.usageError(ase.getLocalizedMessage(), mode, false); die = ase; } catch (UnrecognizedOptionException uoe) { Formatter.usageError(uoe.getLocalizedMessage(), mode, false); die = uoe; } catch (ParseException e) { Formatter.printStackTrace(e); die = e; } if (dieOnFailure && die != null) { System.exit(-1); } else if (!dieOnFailure && die != null) { throw new Exception("Failed to initialize Configuration", die); } return cli; }
From source file:org.ietr.preesm.cli.CLIWorkflowExecutor.java
@Override public Object start(IApplicationContext context) throws Exception { Options options = getCommandLineOptions(); try {// ww w . jav a 2 s. co m CommandLineParser parser = new PosixParser(); String cliOpts = StringUtils .join((Object[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS), " "); CLIWorkflowLogger.traceln("Starting workflows execution"); CLIWorkflowLogger.traceln("Command line arguments: " + cliOpts); // parse the command line arguments CommandLine line = parser.parse(options, (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS)); if (line.getArgs().length != 1) { throw new ParseException("Expected project name as first argument", 0); } // Get the project containing the scenarios and workflows to execute String projectName = line.getArgs()[0]; IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); project = root.getProject(new Path(projectName).lastSegment()); // Handle options String workflowPath = line.getOptionValue('w'); String scenarioPath = line.getOptionValue('s'); // Set of workflows to execute Set<String> workflowPaths = new HashSet<String>(); // Set of scenarios to execute Set<String> scenarioPaths = new HashSet<String>(); // If paths to workflow and scenario are not specified using // options, find them in the project given as arguments if (workflowPath == null) { // If there is no workflow path specified, execute all the // workflows (files with workflowExt) found in workflowDir of // the project workflowPaths = getAllFilePathsIn(workflowExt, project, workflowDir); } else { // Otherwise, format the workflowPath and execute it if (!workflowPath.contains(projectName)) workflowPath = projectName + workflowDir + "/" + workflowPath; if (!workflowPath.endsWith(workflowExt)) workflowPath = workflowPath + "." + workflowExt; workflowPaths.add(workflowPath); } if (scenarioPath == null) { // If there is no scenario path specified, execute all the // scenarios (files with scenarioExt) found in scenarioDir of // the project scenarioPaths = getAllFilePathsIn(scenarioExt, project, scenarioDir); } else { // Otherwise, format the scenarioPath and execute it if (!scenarioPath.contains(projectName)) scenarioPath = projectName + scenarioDir + "/" + scenarioPath; if (!scenarioPath.endsWith(scenarioExt)) scenarioPath = scenarioPath + "." + scenarioExt; scenarioPaths.add(scenarioPath); } CLIWorkflowLogger.traceln("Launching workflows execution"); // Launch the execution of the workflos with the scenarios DFToolsWorkflowLogger.runFromCLI(); for (String wPath : workflowPaths) { for (String sPath : scenarioPaths) { CLIWorkflowLogger .traceln("Launching execution of workflow: " + wPath + " with scenario: " + sPath); execute(wPath, sPath, null); } } } catch (UnrecognizedOptionException uoe) { printUsage(options, uoe.getLocalizedMessage()); } catch (ParseException exp) { printUsage(options, exp.getLocalizedMessage()); } return IApplication.EXIT_OK; }