List of usage examples for org.apache.commons.cli GnuParser GnuParser
GnuParser
From source file:de.akquinet.dustjs.DustEngine.java
public static void main(String[] args) throws URISyntaxException { Options cmdOptions = new Options(); cmdOptions.addOption(DustOptions.CHARSET_OPTION, true, "Input file charset encoding. Defaults to UTF-8."); cmdOptions.addOption(DustOptions.DUST_OPTION, true, "Path to a custom dust.js for Rhino version."); try {//from w w w . j a v a2s . c o m CommandLineParser cmdParser = new GnuParser(); CommandLine cmdLine = cmdParser.parse(cmdOptions, args); DustOptions options = new DustOptions(); if (cmdLine.hasOption(DustOptions.CHARSET_OPTION)) { options.setCharset(cmdLine.getOptionValue(DustOptions.CHARSET_OPTION)); } if (cmdLine.hasOption(DustOptions.DUST_OPTION)) { options.setDust(new File(cmdLine.getOptionValue(DustOptions.DUST_OPTION)).toURI().toURL()); } DustEngine engine = new DustEngine(options); String[] files = cmdLine.getArgs(); String src = null; if (files == null || files.length == 0) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringWriter sw = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while (-1 != (n = in.read(buffer))) { sw.write(buffer, 0, n); } src = sw.toString(); } if (src != null && !src.isEmpty()) { System.out.println(engine.compile(src, "test")); return; } if (files.length == 1) { System.out.println(engine.compile(new File(files[0]))); return; } if (files.length == 2) { engine.compile(new File(files[0]), new File(files[1])); return; } } catch (IOException ioe) { System.err.println("Error opening input file."); } catch (ParseException pe) { System.err.println("Error parsing arguments."); } HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar dust-engine.jar input [output] [options]", cmdOptions); System.exit(1); }
From source file:fr.inria.atlanmod.instantiator.SpecimenGenerator.java
public static void main(String[] args) throws GenerationException, IOException { Options options = new Options(); configureOptions(options);/*from ww w. j a v a 2 s .com*/ CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, args); String metamodel = commandLine.getOptionValue(METAMODEL); DefaultModelGenerator modelGen = new DefaultModelGenerator(URI.createFileURI(metamodel)); if (commandLine.hasOption(ADDITIONAL_METAMODEL)) { for (String additionalMetamodel : commandLine.getOptionValues(ADDITIONAL_METAMODEL)) { URI additionalMetamodelUri = URI.createFileURI(additionalMetamodel); Resource resource = new XMIResourceImpl(additionalMetamodelUri); resource.load(Collections.emptyMap()); registerPackages(resource); } } if (commandLine.hasOption(OUTPUT_DIR)) { String outDir = commandLine.getOptionValue(OUTPUT_DIR); modelGen.setSamplesPath(Paths.get(outDir)); } else { modelGen.setSamplesPath(Paths.get(".")); } if (commandLine.hasOption(N_MODELS)) { int models = ((Number) commandLine.getParsedOptionValue(N_MODELS)).intValue(); modelGen.setSetSize(new int[] { models }); } else { modelGen.setSetSize(new int[] { 1 }); } if (commandLine.hasOption(SIZE)) { long size = ((Number) commandLine.getParsedOptionValue(SIZE)).longValue(); modelGen.setModelsSize(new long[] { size }); } else { modelGen.setModelsSize(new long[] { 1000 }); } if (commandLine.hasOption(SEED)) { long seed = ((Number) commandLine.getParsedOptionValue(SEED)).longValue(); modelGen.setSeed(seed); } else { modelGen.setSeed(System.currentTimeMillis()); } modelGen.runGeneration(); } catch (ParseException e) { System.err.println(e.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new OptionComarator<Option>()); try { formatter.setWidth(Math.max(TerminalFactory.get().getWidth(), 80)); } catch (Throwable t) { // Nothing to do... } ; formatter.printHelp("java -jar <this-file.jar>", options, true); } }
From source file:com.ctriposs.rest4j.tools.idlgen.Rest4JResourceModelExporterCmdLineApp.java
/** * @param args rest4jexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir] *//*from www .j a v a 2 s . co m*/ public static void main(String[] args) { // args = new String[] {"-name", "groups", // "-resourcepackages", "com.ctriposs.groups.server.rest1.impl com.ctriposs.groups.server.rest2.impl ", // "-resourceclasses", "com.ctriposs.groups.server.restX.impl.FooResource", // "-sourcepath", "src/main/java", // "-outdir", "src/codegen/idl", // "-split"}; CommandLine cl = null; try { final CommandLineParser parser = new GnuParser(); cl = parser.parse(OPTIONS, args); } catch (ParseException e) { System.err.println("Invalid arguments: " + e.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "rest4jexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]" + "[-name api_name] [-outdir outdir]", OPTIONS); System.exit(0); } try { new Rest4JResourceModelExporter().export(cl.getOptionValue("name"), null, cl.getOptionValues("sourcepath"), cl.getOptionValues("resourcepackages"), cl.getOptionValues("resourceclasses"), cl.getOptionValue("outdir", ".")); } catch (Throwable e) { log.error("Error writing IDL files", e); System.exit(1); } }
From source file:cloud.elasticity.elastman.App.java
/** * The entry point to the ElastMan main program. * //from w w w. ja v a2s. c om * @param args The first argument is the mode which can be inter, ident, or control * corresponding to interactive mode, system identification mode, or control mode. * The second argument is the configuration file * The third argument is password password */ public static void main(String[] args) { // 1) parse the command line // For more information http://commons.apache.org/cli/ Options options = new Options(); options.addOption("i", "ident", false, "Enter system identification mode."); options.addOption("c", "control", false, "Enter controller mode."); options.addOption("o", "options", true, "Configuration file. Default elastman.conf"); options.addOption("u", "username", true, "Username in the form Tenant:UserName"); options.addOption("p", "password", true, "User password"); options.addOption("k", "keyname", true, "Name of SSH key to use"); options.addOption("z", "zone", true, "The OpenStack availability zone such as the default RegionOne"); options.addOption("e", "endpoint", true, "The URL to access OpenStack API such as http://192.168.1.1:5000/v2.0/"); options.addOption("s", "syncserver", true, "The URL access the WebSyncServer"); options.addOption("h", "help", false, "Print this help"); CommandLineParser parser = new GnuParser(); try { cmd = parser.parse(options, args); } catch (ParseException e2) { System.out.println(e2.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ElastMan", options, true); System.exit(1); } // if h then show help and exit if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ElastMan", options, true); System.exit(0); } // 2) Try to load the properties file. // Command line arguments override settings in the properties file // If no properties file exists. defaults will be used String filename = "control.prop"; // the default file name if (cmd.hasOption("o")) { filename = cmd.getOptionValue("o"); } Props.load(filename, cmd); // Props.save(filename); // System.exit(-1); // 3) If no password in command line nor in config file then ask the user if (Props.password == null) { Console cons; char[] passwd; if ((cons = System.console()) != null && // more secure and without echo! (passwd = cons.readPassword("[%s]", "Password:")) != null) { Props.password = new String(passwd); } else { // if you don't have a console! E.g., Running in eclipse System.out.print("Password: "); Props.password = scanner.nextLine(); } } // 4) Start the UI App app = new App(); app.textUI(args); }
From source file:edu.duke.igsp.gkde.Main.java
public static void main(String[] argv) throws Exception { Options opts = new Options(); opts.addOption("s", true, "wiggle track step (default=1)"); opts.addOption("l", true, "feature length (default=600)"); opts.addOption("f", true, "fragment size (default=estimated from data)"); // opts.addOption("b", true, "bandwidth (default=200)"); // opts.addOption("w", true, "window (default=3800"); opts.addOption("wg", true, "wg threshold set (defualt = calculated)"); opts.addOption("c", true, "genomic total read weight (defualt = calculated)"); opts.addOption("h", false, "print usage"); opts.addOption(OptionBuilder.withArgName("input dir").hasArg() .withDescription("input directory (default=current directory)").isRequired(false).create("d")); opts.addOption(OptionBuilder.withArgName("output dir").hasArg() .withDescription("output directory (default=current directory)").isRequired(false).create("o")); opts.addOption(OptionBuilder.withArgName("background dir").hasArg() .withDescription("background directory (default=none)").isRequired(false).create("b")); opts.addOption(OptionBuilder.withArgName("ploidy dir").hasArg() .withDescription("ploidy/input directory (default=none)").isRequired(false).create("p")); opts.addOption(OptionBuilder.withArgName("wig | bed | npf").hasArg() .withDescription("output format (default wig)").isRequired(false).create("of")); opts.addOption(OptionBuilder.withArgName("dnase | chip | faire | atac").hasArg() .withDescription("input data").isRequired(true).create("in")); opts.addOption(OptionBuilder.withArgName("weight clip").hasArg() .withDescription("weight clip value (default none)").isRequired(false).create("wc")); opts.addOption("t", true, "threshold (standard deviations) (default=4.0)"); // opts.addOption("r", true, "background ratio (default=2.0)"); opts.addOption("v", false, "verbose output"); CommandLineParser parser = new GnuParser(); int fragment_size = -1; int fragment_offset = 0; long featureLength = 600l; // float thresh = 2; float threshold = KDEChromosome.Settings.DEFAULT_THRESHOLD; int step = 1; boolean showHelp = false; boolean verbose = false; String inputDirectory = null; String backgroundDirectory = null; String ploidyDirectory = null; String[] files = null;/*from w ww.j ava 2 s. co m*/ String[] bgfiles = {}; String[] ipfiles = {}; String outputFormat = "wig"; String inputDataType = "dnase"; File outputDirectory = new File(System.getProperty("user.dir")); long bandwidth = 0l; long window = 0l; double ncuts = 0.0d; float temp_threshold = 0f; int weight_clip = 0; System.out.println("F-Seq Version 1.85"); try { CommandLine cmd = parser.parse(opts, argv); showHelp = (cmd.hasOption("h")); verbose = (cmd.hasOption("v")); if (cmd.hasOption("s")) step = Integer.parseInt(cmd.getOptionValue("s")); if (cmd.hasOption("f")) fragment_size = Integer.parseInt(cmd.getOptionValue("f")); if (cmd.hasOption("d")) //input directory inputDirectory = cmd.getOptionValue("d"); if (cmd.hasOption("b")) //background directory backgroundDirectory = cmd.getOptionValue("b"); if (cmd.hasOption("p")) //ploidy|input directory ploidyDirectory = cmd.getOptionValue("p"); if (cmd.hasOption("l")) // bandwidth featureLength = Long.parseLong(cmd.getOptionValue("l")); if (cmd.hasOption("of")) { // output format outputFormat = cmd.getOptionValue("of"); if (!outputFormat.equals("wig") && !outputFormat.equals("bed") && !outputFormat.equals("npf")) { System.out.println("Parameter error: output format must be 'wig' or 'bed'."); showHelp = true; } } if (cmd.hasOption("in")) { // input data type inputDataType = cmd.getOptionValue("in"); if (!inputDataType.equals("dnase") && !inputDataType.equals("chip") && !inputDataType.equals("faire") && !inputDataType.equals("atac")) { System.out.println( "Parameter error: input data type must be 'dnase', 'chip', 'faire', or 'atac'."); showHelp = true; } } if (cmd.hasOption("wc")) { // weight clip weight_clip = Integer.parseInt(cmd.getOptionValue("wc")); } if (cmd.hasOption("t")) { // threshold (standard deviations) threshold = Float.parseFloat(cmd.getOptionValue("t")); } if (cmd.hasOption("o")) { // output directory String out = cmd.getOptionValue("o"); outputDirectory = new File(out); if (!outputDirectory.exists() && !outputDirectory.isDirectory()) { System.out.println("Output directory '" + out + "' is not a valid directory."); showHelp = true; } } if (cmd.hasOption("wg")) temp_threshold = Float.parseFloat(cmd.getOptionValue("wg")); if (cmd.hasOption("c")) ncuts = Double.parseDouble(cmd.getOptionValue("c")); // TESTING ONLY // if(cmd.hasOption("w")) // window // window = Long.parseLong(cmd.getOptionValue("w")); //if(cmd.hasOption("b")) // window // bandwidth = Long.parseLong(cmd.getOptionValue("b")); files = cmd.getArgs(); // input files //bgfiles = cmd.getArgs(); // background files } catch (Exception e) { System.out.println("Error parsing arguments: " + e.getMessage()); e.printStackTrace(); showHelp = true; } if (showHelp || (inputDirectory == null && files.length == 0)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fseq [options]... [file(s)]...", opts); System.exit(1); } File[] pfiles = getFiles(inputDirectory, files); File[] background_files = getFiles(backgroundDirectory, bgfiles); File[] ploidy_files = getFiles(ploidyDirectory, ipfiles); KDEChromosome[] chrs = null; // assume all files are of the same type, if not we'll get parsing errors String path = pfiles[0].getPath(); String extension = path.substring(path.lastIndexOf('.')).toLowerCase(); System.out.println("Path: " + path + ", extension: " + extension); if (extension.equals(".bed")) { System.out.println("Parsing BED file."); chrs = BedReader.read(pfiles); } else if (extension.equals(".sam") || extension.equals(".bam")) { System.out.println("Parsing SAM/BAM file."); chrs = SamReader.read(pfiles, weight_clip); } //KDEChromosome[] input = BedReader.read(ifiles); //compute fragment offset if (fragment_size == -1) { fragment_size = wgShiftCalc(chrs); } fragment_offset = (int) (fragment_size / 2); if (ncuts == 0.0d) { for (int i = 0; i < chrs.length; ++i) { // computes the total read weight of all cuts on a chromosome ncuts += chrs[i].getTotalWeight(); } } KDEChromosome.Settings settings = null; if (bandwidth > 0 || window > 0) { settings = new KDEChromosome.Settings(bandwidth, window, threshold, fragment_offset, ncuts, inputDataType); } else { settings = new KDEChromosome.Settings(featureLength, threshold, fragment_offset, ncuts, inputDataType); } float wg_threshold = wgThreshold(settings, chrs); if (temp_threshold != 0f) { wg_threshold = temp_threshold; } //KDEChromosome.Settings bg_settings = null; //bg_settings = new KDEChromosome.Settings(featureLength*2, threshold, fragment_offset); //int background_size = 0; //int input_size = 0; //float bg_ratio = 0; //float sd = 0; if (verbose) { System.out.println("Settings: "); System.out.println("\twindow=" + (settings.window * 2)); System.out.println("\tbandwidth=" + (settings.bandwidth)); //System.out.println("\tfragment offset=" + (settings.offset)); System.out.println("\tthreshold = " + wg_threshold); System.out.println("\test. fragment size = " + fragment_size); System.out.println("\tsequence length = " + chrs[0].getSequenceLength()); } // if(backgroundDirectory != null) { // for(int i = 0; i < input.length; ++i) { // background_size += input[i].getLength(); // } // for(int i = 0; i < chrs.length; ++i) { // input_size += chrs[i].getLength(); // } // bg_ratio = (float)input_size/(float)background_size; // sd = computeSD(bg_settings, input); // //System.out.println("Sample Ratio: " + bg_ratio); // //System.out.println("Input Size: " + input_size); // //System.out.println("Background Size: " + background_size); // //System.out.println("Input standard deviation: " + (settings.threshold * (float)Math.sqrt((double)bg_ratio * (double)sd * (double)sd))); // //System.out.println("Data standard deviation: " + settings.threshold * computeSD(settings, chrs)); // } for (int i = 0; i < chrs.length; ++i) { if (chrs[i].getFirstPos() == chrs[i].getLastPos()) { System.out.println("Warning: " + chrs[i].getChromosome() + " has size zero. Skipping."); continue; } File ofile = Util.makeUniqueFileWithExtension(outputDirectory, chrs[i].getChromosome(), outputFormat); DensityWriter dw = null; if (outputFormat.equals("wig")) { dw = new WiggleDensityWriter(ofile, chrs[i].getChromosome(), chrs[i].getFirstPos(), step); } else { if (outputFormat.equals("npf")) { dw = new NpfDensityWriter(ofile, chrs[i].getChromosome(), chrs[i].getFirstPos(), step); } else { dw = new BedDensityWriter(ofile, chrs[i].getChromosome(), chrs[i].getFirstPos(), step); } } //Function takes all? or new function for each? // if(backgroundDirectory != null) { // boolean hit = false; // for(int j = 0; j < background_files.length; ++j) { // if(background_files[j].getName().equals(chrs[i].getChromosome() + ".bff")) { // System.out.println("Running background on Chromosome " + chrs[i].getChromosome()); // chrs[i].runBG(settings, dw, verbose, wg_threshold, background_files[j]); // hit = true; // } // } // if(!hit) // System.out.println("No background for Chromosome " + chrs[i].getChromosome()); // } else { // if(ploidyDirectory !=) // chrs[i].run(settings, dw, verbose, wg_threshold); // } chrs[i].run(settings, dw, verbose, wg_threshold, background_files, ploidy_files); dw.close(); } //kde.showGraph(); }
From source file:co.turnus.analysis.bottlenecks.AlgorithmicBottlenecksCliLauncher.java
public static void main(String[] args) { try {/*from www . j a va 2 s . co m*/ CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(cliOptions, args); Configuration config = parseCommandLine(cmd); // init models AnalysisActivator.init(); // set logger verbosity if (config.getBoolean(VERBOSE, false)) { TurnusLogger.setLevel(TurnusLevel.ALL); } // load trace project File tDir = new File(config.getString(TRACE_PROJECT)); TraceProject project = TraceProject.load(tDir); // load profiling weights File wFile = new File(config.getString(PROFILING_WEIGHTS)); ProfilingWeights weights = new XmlProfilingWeightsReader().read(project.getNetwork(), wFile); // build the trace weighter StatisticalTraceWeighter tw = new StatisticalTraceWeighter(); tw.configure(weights, ActionWeightsDistribution.class); // run the analysis AlgorithmicBottlenecks ab = new AlgorithmicBottlenecks(project, tw); ab.setConfiguration(config); AlgoBottlenecksData data = ab.run(); TurnusLogger.info("Storing results..."); File outPath = new File(config.getString(OUTPUT_PATH)); // store the analysis report String uuid = UUID.randomUUID().toString(); File rFile = new File(outPath, uuid + "." + TurnusExtension.REPORT); Report report = DataFactory.eINSTANCE.createReport(); report.setDate(new Date()); report.setComment("Report with only Algorithmic Bottlenecks results analysis"); report.getDataSet().add(data); EcoreHelper.storeEObject(report, new ResourceSetImpl(), rFile); TurnusLogger.info("TURNUS report stored in " + rFile); // store formatted reports String xlsName = config.getString(XLS, ""); if (!xlsName.isEmpty()) { File xlsFile = new File(outPath, xlsName + ".xls"); new XlsAlgoBottlenecksDataWriter().write(data, xlsFile); TurnusLogger.info("XLS report stored in " + xlsFile); } TurnusLogger.info("Analysis Done!"); } catch (ParseException e) { TurnusLogger.error(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(AlgorithmicBottlenecksCliLauncher.class.getSimpleName(), cliOptions); } catch (Exception e) { TurnusLogger.error(e.getMessage()); } }
From source file:es.tid.fiware.fiwareconnectors.cygnus.nodes.CygnusApplication.java
/** * Main application to be run when this CygnusApplication is invoked. The only differences with the original one * are the CygnusApplication is used instead of the Application one, and the Management Interface port option in * the command line.//from w w w . ja v a 2s .co m * @param args */ public static void main(String[] args) { try { Options options = new Options(); Option option = new Option("n", "name", true, "the name of this agent"); option.setRequired(true); options.addOption(option); option = new Option("f", "conf-file", true, "specify a conf file"); option.setRequired(true); options.addOption(option); option = new Option(null, "no-reload-conf", false, "do not reload " + "conf file if changed"); options.addOption(option); option = new Option("h", "help", false, "display help text"); options.addOption(option); option = new Option("p", "mgmt-if-port", true, "the management interface port"); option.setRequired(false); options.addOption(option); CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); File configurationFile = new File(commandLine.getOptionValue('f')); String agentName = commandLine.getOptionValue('n'); boolean reload = !commandLine.hasOption("no-reload-conf"); if (commandLine.hasOption('h')) { new HelpFormatter().printHelp("flume-ng agent", options, true); return; } // if int mgmtIfPort = 8081; // default value if (commandLine.hasOption('p')) { mgmtIfPort = new Integer(commandLine.getOptionValue('p')).intValue(); } // if // the following is to ensure that by default the agent will fail on startup if the file does not exist if (!configurationFile.exists()) { // if command line invocation, then need to fail fast if (System.getProperty(Constants.SYSPROP_CALLED_FROM_SERVICE) == null) { String path = configurationFile.getPath(); try { path = configurationFile.getCanonicalPath(); } catch (IOException ex) { logger.error("Failed to read canonical path for file: " + path, ex); } // try catch throw new ParseException("The specified configuration file does not exist: " + path); } // if } // if List<LifecycleAware> components = Lists.newArrayList(); CygnusApplication application; if (reload) { EventBus eventBus = new EventBus(agentName + "-event-bus"); PollingPropertiesFileConfigurationProvider configurationProvider = new PollingPropertiesFileConfigurationProvider( agentName, configurationFile, eventBus, 30); components.add(configurationProvider); application = new CygnusApplication(components, mgmtIfPort); eventBus.register(application); } else { PropertiesFileConfigurationProvider configurationProvider = new PropertiesFileConfigurationProvider( agentName, configurationFile); application = new CygnusApplication(mgmtIfPort); application.handleConfigurationEvent(configurationProvider.getConfiguration()); } // if else application.start(); final CygnusApplication appReference = application; Runtime.getRuntime().addShutdownHook(new Thread("agent-shutdown-hook") { @Override public void run() { appReference.stop(); } // run }); } catch (Exception e) { logger.error("A fatal error occurred while running. Exception follows.", e); } // try catch }
From source file:de.prozesskraft.pkraft.Commitit.java
public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException { // try/*from ww w .ja v a 2 s . c o m*/ // { // if (args.length != 3) // { // System.out.println("Please specify processdefinition file (xml) and an outputfilename"); // } // // } // catch (ArrayIndexOutOfBoundsException e) // { // System.out.println("***ArrayIndexOutOfBoundsException: Please specify processdefinition.xml, openoffice_template.od*, newfile_for_processdefinitions.odt\n" + e.toString()); // } /*---------------------------- get options from ini-file ----------------------------*/ java.io.File inifile = new java.io.File( WhereAmI.getInstallDirectoryAbsolutePath(Commitit.class) + "/" + "../etc/pkraft-commitit.ini"); if (inifile.exists()) { try { ini = new Ini(inifile); } catch (InvalidFileFormatException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { System.err.println("ini file does not exist: " + inifile.getAbsolutePath()); System.exit(1); } /*---------------------------- create boolean options ----------------------------*/ Option ohelp = new Option("help", "print this message"); /*---------------------------- create argument options ----------------------------*/ Option oinstance = OptionBuilder.withArgName("FILE").hasArg() .withDescription("[mandatory] process instance file") // .isRequired() .create("instance"); Option ostep = OptionBuilder.withArgName("STEPNAME").hasArg() .withDescription("[optional, default: root] process step to commit to") // .isRequired() .create("step"); Option ofile = OptionBuilder.withArgName("FILE").hasArg() .withDescription("[optional] this file will be committed as file. key will be set to 'default'") // .isRequired() .create("file"); Option okey = OptionBuilder.withArgName("KEY").hasArg() .withDescription( "[optional, default: default] this string will be considered as the key for the commit.") // .isRequired() .create("key"); Option ovariable = OptionBuilder.withArgName("VALUE").hasArg() .withDescription("[optional] this string will be committed as a variable.") // .isRequired() .create("variable"); /*---------------------------- create options object ----------------------------*/ Options options = new Options(); options.addOption(ohelp); options.addOption(oinstance); options.addOption(ostep); options.addOption(ofile); options.addOption(okey); options.addOption(ovariable); /*---------------------------- create the parser ----------------------------*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments commandline = parser.parse(options, args); } catch (Exception exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); exiter(); } /*---------------------------- usage/help ----------------------------*/ if (commandline.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("commit", options); System.exit(0); } /*---------------------------- ueberpruefen ob eine schlechte kombination von parametern angegeben wurde ----------------------------*/ if (!(commandline.hasOption("instance"))) { System.out.println("option -instance is mandatory."); exiter(); } else if (!(commandline.hasOption("dir")) && !(commandline.hasOption("file")) && !(commandline.hasOption("varfile")) && !(commandline.hasOption("varname")) && !(commandline.hasOption("varvalue")) && !(commandline.hasOption("variable"))) { System.out.println( "at least one of these options needed. -dir -file -varfile -variable -varname -varvalue."); exiter(); } else if ((commandline.hasOption("varname") && !(commandline.hasOption("varvalue"))) || (!(commandline.hasOption("varname")) && commandline.hasOption("varvalue"))) { System.out.println("use options -varname and -varvalue only in combination with each other."); exiter(); } /*---------------------------- die lizenz ueberpruefen und ggf abbrechen ----------------------------*/ // check for valid license ArrayList<String> allPortAtHost = new ArrayList<String>(); allPortAtHost.add(ini.get("license-server", "license-server-1")); allPortAtHost.add(ini.get("license-server", "license-server-2")); allPortAtHost.add(ini.get("license-server", "license-server-3")); MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1"); // lizenz-logging ausgeben for (String actLine : (ArrayList<String>) lic.getLog()) { System.err.println(actLine); } // abbruch, wenn lizenz nicht valide if (!lic.isValid()) { System.exit(1); } /*---------------------------- die eigentliche business logic ----------------------------*/ // setzen des steps String stepname = "root"; if (commandline.hasOption("step")) { stepname = commandline.getOptionValue("step"); } // setzen des key String key = "default"; if (commandline.hasOption("key")) { key = commandline.getOptionValue("key"); } Process p1 = new Process(); p1.setInfilebinary(commandline.getOptionValue("instance")); System.out.println("info: reading process instance " + commandline.getOptionValue("instance")); Process p2 = p1.readBinary(); p2.setOutfilebinary(commandline.getOptionValue("instance")); // step ueber den namen heraussuchen Step step = p2.getStep(stepname); if (step == null) { System.err.println("step not found: " + stepname); exiter(); } // den Commit 'by-process-commitit' heraussuchen oder einen neuen Commit dieses Namens erstellen Commit commit = step.getCommit("by-hand"); if (commit == null) { commit = new Commit(step); commit.setName("by-process-commitit"); } // committen if (commandline.hasOption("file")) { File file = new File(); file.setKey(key); file.setGlob(commandline.getOptionValue("file")); commit.addFile(file); commit.doIt(); } if (commandline.hasOption("variable")) { Variable variable = new Variable(); variable.setKey(key); variable.setValue(commandline.getOptionValue("variable")); commit.addVariable(variable); commit.doIt(); } p2.writeBinary(); System.out.println("info: writing process instance " + p2.getOutfilebinary()); }
From source file:main.RankerOCR.java
/** * Command line interface for RankerOCR. * <p>/*ww w .j a v a 2 s . c o m*/ * <b>Command line input:</b> * <ul> * usage: java -jar Ranker-OCR [options] * </ul> * <b>Options list:</b> * <ul> * <li>-gui Launch a graphical user interface</li> * <li>-help Show the help</li> * <li>-indoc1 [arg] Set the file name of the original document</li> * <li>-indoc2 [arg] Set the file name of the document to compare</li> * <li>-ranker [arg] Set the ranker used for the comparison</li> * <li>-outdoc [arg] Set the document where write the results</li> * <li>-separator [arg] Set the delimiter char use in the CSV out file</li> * </ul> * <b>Return values are if error:</b> * <ul> * <li>(-1) The precision parameter is not a number.</li> * <li>(-2) The precision parameter is lower than 0.</li> * <li>(-3) The precision parameter is greater than 10.</li> * <li>(-11) The ranker name is wrong</li> * <li>(-21) The separator char is empty</li> * <li>(-22) The separator is not a char</li> * <li>(-31) File name doesn't exist</li> * <li>(-32) File name is not a file</li> * <li>(-33) Error when access to documents files</li> * <li>(-34) Output file can not be write</li> * <li>(-35) Output file can not be created</li> * <li>(-41) Error when parsing parameters</li> * <li>(-100) Internal error when creating the ranker. Please report a * bug</li> * <li>(-101) Internal error when get the ranker list. Please report a * bug.</li> * <li>(-102) Error when access to help file. Please report a bug.</li> * </ul> * <p> * @param args Argument array which can have the values from options list */ public static void main(String[] args) { //Parse command line CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { showHelp(hf, options); } else if (cmd.hasOption("gui")) { display.DispalyRankerOCR.main(new String[] {}); } else if (cmd.hasOption("indoc1") && cmd.hasOption("indoc2") && cmd.hasOption("outdoc")) { //<editor-fold defaultstate="collapsed" desc="Rank documents"> //Prepare parameter Class ranker = evalRanker(cmd.getOptionValue("ranker", "SimpleRanker")); char separator = evalSeparator(cmd.getOptionValue("separator", "\t")); File f1 = evalInputFile(cmd.getOptionValue("indoc1", "")); File f2 = evalInputFile(cmd.getOptionValue("indoc2", "")); File f3 = evalOutputFile(cmd.getOptionValue("outdoc", ""), separator); //Read file String s1 = readInputDocText(f1); String s2 = readInputDocText(f2); //Compare file double percent = rankDocuments(s1, s2, ranker); //Write result String[] s = { Double.toString(percent), ranker.getSimpleName(), f1.getName(), f2.getName(), f1.getParent(), f2.getParent(), new Date().toString() }; writeOutpuDocCsv(f3, separator, s); //</editor-fold> } else { printFormated("java -jar Ranker-OCR [options] please type " + "-help for more info"); } } catch (ParseException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-41); } }
From source file:backtype.storm.command.gray_upgrade.java
public static void main(String[] args) throws Exception { if (args == null || args.length < 1) { System.out.println("Invalid parameter"); usage();//w ww . j a v a 2 s.co m return; } String topologyName = args[0]; String[] str2 = Arrays.copyOfRange(args, 1, args.length); CommandLineParser parser = new GnuParser(); Options r = buildGeneralOptions(new Options()); CommandLine commandLine = parser.parse(r, str2, true); int workerNum = 0; String component = null; List<String> workers = null; if (commandLine.hasOption("n")) { workerNum = Integer.valueOf(commandLine.getOptionValue("n")); } if (commandLine.hasOption("p")) { component = commandLine.getOptionValue("p"); } if (commandLine.hasOption("w")) { String w = commandLine.getOptionValue("w"); if (!StringUtils.isBlank(w)) { workers = Lists.newArrayList(); String[] parts = w.split(","); for (String part : parts) { if (part.split(":").length == 2) { workers.add(part.trim()); } } } } upgradeTopology(topologyName, component, workers, workerNum); }