public void test11456() { // Posix Options options = new Options(); options.addOption(OptionBuilder.hasOptionalArg().create('a')); options.addOption(OptionBuilder.hasArg().create('b')); String[] args = new String[] {"-a", "-bvalue"}; CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); assertEquals(cmd.getOptionValue('b'), "value"); } catch (ParseException exp) { fail("Unexpected Exception: " + exp.getMessage()); } // GNU options = new Options(); options.addOption(OptionBuilder.hasOptionalArg().create('a')); options.addOption(OptionBuilder.hasArg().create('b')); args = new String[] {"-a", "-b", "value"}; parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); assertEquals(cmd.getOptionValue('b'), "value"); } catch (ParseException exp) { fail("Unexpected Exception: " + exp.getMessage()); } }
public void test15046() throws Exception { CommandLineParser parser = new PosixParser(); final String[] CLI_ARGS = new String[] {"-z", "c"}; Option option = new Option("z", "timezone", true, "affected option"); Options cliOptions = new Options(); cliOptions.addOption(option); parser.parse(cliOptions, CLI_ARGS); // now add conflicting option cliOptions.addOption("c", "conflict", true, "conflict option"); CommandLine line = parser.parse(cliOptions, CLI_ARGS); assertEquals(option.getValue(), "c"); assertTrue(!line.hasOption("c")); }
/** * Processing the input command line arguments * * @param args a list of pride db accessions */ private void processCmdArgs(String[] args) { try { // parse command line input CommandLine cmd = cmdParser.parse(cmdOptions, args); // get accessions java.util.List<Comparable> accs = null; if (cmd.hasOption(ACCESSION_CMD)) { String accStr = cmd.getOptionValue(ACCESSION_CMD); accs = new ArrayList<Comparable>(AccessionUtils.expand(accStr)); } // get user name String username = null; if (cmd.hasOption(USER_NAME_CMD)) { username = cmd.getOptionValue(USER_NAME_CMD); } // get password String password = null; if (cmd.hasOption(PASSWORD_CMD)) { password = cmd.getOptionValue(PASSWORD_CMD); } if (accs != null || username != null) { OpenValidPrideExperimentTask task = new OpenValidPrideExperimentTask(accs, username, password); task.setGUIBlocker(new DefaultGUIBlocker(task, GUIBlocker.Scope.NONE, null)); getDesktopContext().addTask(task); } } catch (ParseException e) { System.err.println("Parsing command line option failed. Reason: " + e.getMessage()); } }
public void init(String[] args) throws UserError { Context.reset(); CommandLineParser globalParser = new GnuParser(); List<String> globalArgs = new ArrayList<String>(); boolean inGlobal = true; for (String arg : args) { if (inGlobal) { if (arg.startsWith("--")) { globalArgs.add(arg); } else { this.command = arg; inGlobal = false; } } else { commandArgs.add(arg); } } try { this.globalArguments = globalParser.parse(globalOptions, globalArgs.toArray(new String[globalArgs.size()])); } catch (ParseException e) { throw new UserError("Error parsing global command line argument: " + e.getMessage()); } }
public static Options parseArgs(String cmdArgs[]) { CommandLineParser parser = new GnuParser(); CmdLineOptions options = getCmdLineOptions(); try { CommandLine cmd = parser.parse(options, cmdArgs, false); if (cmd.hasOption(HELP_OPTION)) { printUsage(options); System.exit(0); } String[] args = cmd.getArgs(); if (args.length == 0) { System.err.println("No sstables to split"); printUsage(options); System.exit(1); } Options opts = new Options(Arrays.asList(args)); opts.debug = cmd.hasOption(DEBUG_OPTION); opts.verbose = cmd.hasOption(VERBOSE_OPTION); opts.snapshot = !cmd.hasOption(NO_SNAPSHOT_OPTION); opts.sizeInMB = DEFAULT_SSTABLE_SIZE; if (cmd.hasOption(SIZE_OPTION)) opts.sizeInMB = Integer.valueOf(cmd.getOptionValue(SIZE_OPTION)); return opts; } catch (ParseException e) { errorMsg(e.getMessage(), options); return null; } }
private static boolean setOptions(String[] lcommand) { Options loptions = new Options(); loptions.addOption(new Option("d", "debug", false, "print debug information (highly verbose)")); loptions.addOption(new Option("o", "stdout", false, "print output files to standard output")); loptions.addOption(new Option("w", "warning", false, "print warning messages")); CommandLineParser clparser = new PosixParser(); try { cmd = clparser.parse(loptions, lcommand); } catch (org.apache.commons.cli.ParseException e) { String mytoolcmd = "java -jar stave.jar"; String myoptlist = " <options> <source files>"; String myheader = "Convert JavaParser's AST to OpenJDK's AST"; String myfooter = "More info: https://github.com/pcgomes/javaparser2jctree"; HelpFormatter formatter = new HelpFormatter(); // formatter.printUsage( new PrintWriter(System.out,true), 100, "java -jar synctask.jar", // loptions ); // formatter.printHelp( mytoolcmd + myoptlist, myheader, loptions, myfooter, false); formatter.printHelp(mytoolcmd + myoptlist, loptions, false); return (false); } return (true); }
public static Options parseArgs(String cmdArgs[]) { CommandLineParser parser = new GnuParser(); CmdLineOptions options = getCmdLineOptions(); try { CommandLine cmd = parser.parse(options, cmdArgs, false); if (cmd.hasOption(HELP_OPTION)) { printUsage(options); System.exit(0); } String[] args = cmd.getArgs(); if (args.length >= 4 || args.length < 2) { String msg = args.length < 2 ? "Missing arguments" : "Too many arguments"; errorMsg(msg, options); System.exit(1); } String keyspace = args[0]; String cf = args[1]; String snapshot = null; if (args.length == 3) snapshot = args[2]; Options opts = new Options(keyspace, cf, snapshot); opts.debug = cmd.hasOption(DEBUG_OPTION); opts.keepSource = cmd.hasOption(KEEP_SOURCE); return opts; } catch (ParseException e) { errorMsg(e.getMessage(), options); return null; } }
public static void main(String args[]) throws IOException, ParseException { Options options = new Options(); options.addOption("u", "uniquehits", false, "only output hits with a single mapping"); options.addOption( "s", "nosuboptimal", false, "do not include hits whose score is not equal to the best score for the read"); CommandLineParser parser = new GnuParser(); CommandLine cl = parser.parse(options, args, false); boolean uniqueOnly = cl.hasOption("uniquehits"); boolean filterSubOpt = cl.hasOption("nosuboptimal"); ArrayList<String[]> lines = new ArrayList<String[]>(); String line; String lastRead = ""; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while ((line = reader.readLine()) != null) { String pieces[] = line.split("\t"); if (!pieces[0].equals(lastRead)) { printLines(lines, uniqueOnly, filterSubOpt); lines.clear(); } lines.add(pieces); lastRead = pieces[0]; } printLines(lines, uniqueOnly, filterSubOpt); }
public void run(String[] args) throws ParseException, TransformationException, IOException, AnalysisException { Options options = new Options(); options.addOption("input", true, "input path"); options.addOption("output", true, "output path"); options.addOption("ext", true, "extension"); CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); String inDir = line.getOptionValue("input"); String outDir = line.getOptionValue("output"); String extension = line.getOptionValue("ext"); File dir = new File(inDir); for (File f : FileUtils.listFiles(dir, new String[] {extension}, true)) { TrueVizToBxDocumentReader tvReader = new TrueVizToBxDocumentReader(); List<BxPage> pages = tvReader.read(new FileReader(f)); BxDocument doc = new BxDocument().setPages(pages); doc.setFilename(f.getName()); BxDocument rewritten = transform(doc); File f2 = new File(outDir + doc.getFilename()); BxDocumentToTrueVizWriter wrt = new BxDocumentToTrueVizWriter(); boolean created = f2.createNewFile(); if (!created) { throw new IOException("Cannot create file: "); } FileWriter fw = new FileWriter(f2); wrt.write(fw, Lists.newArrayList(rewritten)); fw.flush(); fw.close(); } }
public static boolean parseArgs(String[] args) { CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(options, args); if (cmd.hasOption("tbn") && cmd.hasOption("tbp")) { tbUsername = cmd.getOptionValue("tbn"); tbPassword = cmd.getOptionValue("tbp"); } else { System.out.println("Please enter your Topbot username and password"); return false; } if (cmd.hasOption("n")) { numAccounts = Integer.parseInt(cmd.getOptionValue("n")); if (numAccounts >= 9) System.out.println("WARNING: The number of accounts exceeds the number of f2p worlds!"); } else numAccounts = DEFAULT_ACCOUNT_NUM; if (cmd.hasOption("bp")) botPassword = cmd.getOptionValue("bp"); else botPassword = DEFAULT_PW; if (cmd.hasOption("s")) script = cmd.getOptionValue("s"); else script = DEFAULT_SCRIPT; return true; } catch (Exception e) { System.out.println("Couldn't parse arguments"); return false; } }
public static String[] ginit(String[] args) { if (System.getenv("KONOHA_DEBUG") != null) { verboseDebug = true; verboseGc = true; verboseSugar = true; verboseCode = true; } CommandLineParser parser = new BasicParser(); CommandLine commandLine = null; try { commandLine = parser.parse(longOptions, args); } catch (ParseException e) { // TODO } if(commandLine.hasOption("verbose")) { verboseDebug = true; System.out.println("option vervose"); } if(commandLine.hasOption("verbose:gc")) { verboseGc = true; System.out.println("option vervose:gc"); } if(commandLine.hasOption("verbose:sugar")) { verboseSugar = true; System.out.println("option vervose:sugar"); } if(commandLine.hasOption("verbose:code")) { verboseCode = true; System.out.println("option vervose:code"); } if(commandLine.hasOption("interactive")) { interactiveFlag = true; System.out.println("option interactive"); } if(commandLine.hasOption("typecheck")) { compileonlyFlag = true; System.out.println("option typecheck"); } if(commandLine.hasOption("start-with")) { startupScript = commandLine.getOptionValue("start-with"); System.out.println("option start-with"); System.out.println(" with arg " + startupScript); } if(commandLine.hasOption("test")) { testScript = commandLine.getOptionValue("test"); System.out.println(" with arg " + testScript); } if(commandLine.hasOption("test-with")) { testScript = commandLine.getOptionValue("test"); System.out.println(" with arg " + testScript); } if(commandLine.hasOption("builtin-test")) { builtinTest = commandLine.getOptionValue("builtin-test"); System.out.println(" with arg " + builtinTest); } return commandLine.getArgs(); }
// TODO add exception for invalid options private void loadCLO(String[] args) { Options options = new Options(); String[][] clolist = { // {"variable/optionname", "description"}, {"genConfig", "general configuration file location"}, {"inWeightsLoc", "input weights configuration file location"}, {"inDBLoc", "input database file location"}, {"outWeightsLoc", "output weights configuration file location"}, {"outDBLoc", "output database file location"}, {"p3pLocation", "adding to DB: single policy file location"}, {"p3pDirLocation", "adding to DB: multiple policy directory location"}, {"newDB", "create new database in place of old one (doesn't check for existence of old one"}, {"newPolicyLoc", "the policy object to process"}, {"userResponse", "response to specified policy"}, {"userIO", "user interface"}, {"userInit", "initialization via user interface"}, {"policyDB", "PolicyDatabase backend"}, {"cbrV", "CBR to use"}, {"blanketAccept", "automatically accept the user suggestion"}, {"loglevel", "level of things save to the log- see java logging details"}, {"policyDB", "PolicyDatabase backend"}, {"NetworkRType", "Network Resource type"}, {"NetworkROptions", "Network Resource options"}, {"confidenceLevel", "Confidence threshold for consulting a networked resource"}, {"useNet", "use networking options"}, {"loglocation", "where to save the log file"}, {"loglevel", "the java logging level to use. See online documentation for enums."} }; for (String[] i : clolist) { options.addOption(i[0], true, i[1]); } CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error parsing commandline arguments."); e.printStackTrace(); System.exit(3); } /* for(String i : args) { System.err.println(i); } */ for (String[] i : clolist) { if (cmd.hasOption(i[0])) { System.err.println("found option i: " + i); genProps.setProperty(i[0], cmd.getOptionValue(i[0])); } } System.err.println(genProps); }
public void test15648() throws Exception { CommandLineParser parser = new PosixParser(); final String[] args = new String[] {"-m", "\"Two Words\""}; Option m = OptionBuilder.hasArgs().create("m"); Options options = new Options(); options.addOption(m); CommandLine line = parser.parse(options, args); assertEquals("Two Words", line.getOptionValue("m")); }
/** * processes the command line input * * @param args command line arg vector */ public CommandLine parseArgs(final String[] args) throws ProjectToolException { final CommandLineParser parser = new PosixParser(); try { cli = parser.parse(options, args); } catch (ParseException e) { help(); throw new ProjectToolException(e); } initArgs(); return cli; }
public static void parseAndPopulate(Object instance, String input) throws CommandLineParserException, OptionValidatorException { CommandLineParser cl = generateCommandLineParser(instance.getClass()); InvocationProviders invocationProviders = new AeshInvocationProviders( new AeshConverterInvocationProvider(), new AeshCompleterInvocationProvider(), new AeshValidatorInvocationProvider()); cl.getCommandPopulator() .populateObject(instance, cl.parse(input), invocationProviders, null, true); }
public static LoaderOptions parseArgs(String cmdArgs[]) { CommandLineParser parser = new GnuParser(); CmdLineOptions options = getCmdLineOptions(); try { CommandLine cmd = parser.parse(options, cmdArgs, false); if (cmd.hasOption(HELP_OPTION)) { printUsage(options); System.exit(0); } String[] args = cmd.getArgs(); if (args.length == 0) { System.err.println("Missing sstable directory argument"); printUsage(options); System.exit(1); } if (args.length > 1) { System.err.println("Too many arguments"); printUsage(options); System.exit(1); } String dirname = args[0]; File dir = new File(dirname); if (!dir.exists()) errorMsg("Unknown directory: " + dirname, options); if (!dir.isDirectory()) errorMsg(dirname + " is not a directory", options); LoaderOptions opts = new LoaderOptions(dir); opts.debug = cmd.hasOption(DEBUG_OPTION); opts.verbose = cmd.hasOption(VERBOSE_OPTION); opts.noProgress = cmd.hasOption(NOPROGRESS_OPTION); if (cmd.hasOption(IGNORE_NODES_OPTION)) { String[] nodes = cmd.getOptionValue(IGNORE_NODES_OPTION).split(","); try { for (String node : nodes) { opts.ignores.add(InetAddress.getByName(node)); } } catch (UnknownHostException e) { errorMsg(e.getMessage(), options); } } return opts; } catch (ParseException e) { errorMsg(e.getMessage(), options); return null; } }
public CommandLine parse(String[] cmd) { CommandLineParser parser = new ActualPosixParser(); try { setCommandLine(parser.parse(options, cmd)); return getCommandLine(); } catch (ParseException e) { System.out.println("Error while parsing commandline:" + e.getMessage()); } return null; }
public void runCommand(String[] args, boolean tsqlMode) throws Exception { CommandLineParser parser = new PosixParser(); if (args.length == 0) { printUsage(tsqlMode); return; } CommandLine cmd = parser.parse(options, args); String hostName = null; Integer port = null; if (cmd.hasOption("h")) { hostName = cmd.getOptionValue("h"); } if (cmd.hasOption("p")) { port = Integer.parseInt(cmd.getOptionValue("p")); } String param; if (cmd.getArgs().length > 1) { printUsage(tsqlMode); return; } else { param = cmd.getArgs()[0]; } // if there is no "-h" option, if (hostName == null) { if (tajoConf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS) != null) { // it checks if the client service address is given in configuration and distributed mode. // if so, it sets entryAddr. hostName = tajoConf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS).split(":")[0]; } } if (port == null) { if (tajoConf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS) != null) { // it checks if the client service address is given in configuration and distributed mode. // if so, it sets entryAddr. port = Integer.parseInt( tajoConf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS).split(":")[1]); } } if ((hostName == null) ^ (port == null)) { return; } else if (hostName != null && port != null) { tajoConf.setVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, hostName + ":" + port); } processConfKey(writer, param); writer.flush(); }
public void test14786() throws Exception { Option o = OptionBuilder.isRequired().withDescription("test").create("test"); Options opts = new Options(); opts.addOption(o); opts.addOption(o); CommandLineParser parser = new GnuParser(); String[] args = new String[] {"-test"}; CommandLine line = parser.parse(opts, args); assertTrue(line.hasOption("test")); }
public static void main(String[] args) { Main main = new Main(); main.header("Liquibase SDK"); try { main.init(args); if (main.command == null) { throw new UserError("No command passed"); } if (main.command.equals("help")) { main.printHelp(); return; } VagrantControl vagrantControl; if (main.command.equals("vagrant")) { vagrantControl = new VagrantControl(main); } else { throw new UserError("Unknown command: " + main.command); } CommandLineParser commandParser = new GnuParser(); try { CommandLine commandArguments = commandParser.parse( vagrantControl.getOptions(), main.commandArgs.toArray(new String[main.commandArgs.size()])); vagrantControl.execute(commandArguments); } catch (ParseException e) { throw new UserError("Error parsing command arguments: " + e.getMessage()); } main.divider(); main.out("Command executed successfully"); } catch (UserError userError) { main.out(""); main.header("ERROR EXECUTING COMMAND"); main.out(userError.getMessage()); main.out(""); main.out(""); return; } catch (Throwable exception) { System.out.println("Unexpected error: " + exception.getMessage()); exception.printStackTrace(); } }
public void test11457() { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("verbose").create()); String[] args = new String[] {"--verbose"}; CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); assertTrue(cmd.hasOption("verbose")); } catch (ParseException exp) { exp.printStackTrace(); fail("Unexpected Exception: " + exp.getMessage()); } }
public static void main(String[] args) throws Exception { String propertyFile = null; // create the command line parser CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("f", "file", true, "The properties file"); options.addOption("v", "verbose", false, "Verbose logging output"); options.addOption("h", "help", false, "Help output"); try { CommandLine line = parser.parse(options, args); if (line.hasOption('v')) { org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG); } if (line.hasOption('h')) { usage(options); } if (line.hasOption('f')) { propertyFile = line.getOptionValue('f'); } else { throw new Exception("Please supply -f"); } } catch (Exception e) { log.error("Invalid command line: " + e, e); usage(options); } Properties props = new Properties(); props.load(new FileReader(propertyFile)); startFromProperties(props); Runtime.getRuntime() .addShutdownHook( new Thread( new Runnable() { @Override public void run() { log.info("Received shutdown signal. Shutting down..."); server.stop(3); } })); }
private static void parse(String[] args, boolean stopAtNoOption) throws ParseException, IOException { parser = new PosixParser(); commandLine = parser.parse(options, args, stopAtNoOption); // if(commandLine.hasOption("outdir")) { // this.outdir = commandLine.getOptionValue("outdir"); // } // if(commandLine.hasOption("log-level")) { // logger.setLevel(Integer.parseInt(commandLine.getOptionValue("log-level"))); // } if (args.length > 0 && "variation".equals(args[1])) { System.out.println("variation SQL test"); } }
public void test11458() { Options options = new Options(); options.addOption(OptionBuilder.withValueSeparator('=').hasArgs().create('D')); options.addOption(OptionBuilder.withValueSeparator(':').hasArgs().create('p')); String[] args = new String[] {"-DJAVA_HOME=/opt/java", "-pfile1:file2:file3"}; CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); String[] values = cmd.getOptionValues('D'); assertEquals(values[0], "JAVA_HOME"); assertEquals(values[1], "/opt/java"); values = cmd.getOptionValues('p'); assertEquals(values[0], "file1"); assertEquals(values[1], "file2"); assertEquals(values[2], "file3"); java.util.Iterator iter = cmd.iterator(); while (iter.hasNext()) { Option opt = (Option) iter.next(); switch (opt.getId()) { case 'D': assertEquals(opt.getValue(0), "JAVA_HOME"); assertEquals(opt.getValue(1), "/opt/java"); break; case 'p': assertEquals(opt.getValue(0), "file1"); assertEquals(opt.getValue(1), "file2"); assertEquals(opt.getValue(2), "file3"); break; default: fail("-D option not found"); } } } catch (ParseException exp) { fail( "Unexpected Exception:\nMessage:" + exp.getMessage() + "Type: " + exp.getClass().getName()); } }
public static void main(String[] args) { Options options = KeyGenCLI.buildOptions(); HelpFormatter helpFormatter = new HelpFormatter(); CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, args); String service = commandLine.getOptionValue("service"); String key = Crypto.generateAes128KeyWithSeed(service); if (key == null) { throw new Exception("Key was not generated!"); } JSONObject keyObject = new JSONObject(); keyObject.put("name", service); keyObject.put("data", key); System.out.println(String.format("Key: `%s`\n", key)); System.out.println("Key object:"); System.out.println(keyObject.toString()); } catch (MissingOptionException e) { System.out.println("Missing required option(s)!"); helpFormatter.printHelp( "\nKeyGenCLI", "This tool generates a unique key and prints the result.", options, "", true); } catch (UnrecognizedOptionException e) { System.out.println("Unrecognized option!"); helpFormatter.printHelp( "\nKeyGenCLI", "This tool generates a unique key and prints the result.", options, "", true); } catch (ParseException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
public static CommandLine parseCmdLine( final String appName, String[] args, Options options, CommandLineParser parser) { HelpFormatter hf = new HelpFormatter(); hf.setWidth(110); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { hf.printHelp(appName, options, true); return null; } } catch (ParseException e) { hf.printHelp(appName, options, true); } return commandLine; }
private void parseArgs(final String[] args) throws ParseException { final Options options = new Options(); options.addOption("c", "claim", false, "Use Try/Claim"); options.addOption("", "pubChannel", true, "Primary publishing channel"); options.addOption("", "reflectChannel", true, "Reflection channel"); final CommandLineParser parser = new GnuParser(); final CommandLine command = parser.parse(options, args); if (command.hasOption("pubChannel")) { pubChannel = command.getOptionValue("pubChannel", "udp://localhost:44444"); } if (command.hasOption("reflectChannel")) { reflectChannel = command.getOptionValue("reflectChannel", "udp://localhost:55555"); } }
private static Params parse(String[] args) { Options options = generateCommandlineOptions(); CommandLineParser parser = new PosixParser(); Params params = new Params(); try { CommandLine cmd = parser.parse(options, args); String value; if (cmd.hasOption("input")) { params.input = cmd.getOptionValue("input"); } if (cmd.hasOption("maxIter")) { value = cmd.getOptionValue("maxIter"); params.maxIter = Integer.parseInt(value); } if (cmd.hasOption("tol")) { value = cmd.getOptionValue("tol"); params.tol = Double.parseDouble(value); } if (cmd.hasOption("fitIntercept")) { value = cmd.getOptionValue("fitIntercept"); params.fitIntercept = Boolean.parseBoolean(value); } if (cmd.hasOption("regParam")) { value = cmd.getOptionValue("regParam"); params.regParam = Double.parseDouble(value); } if (cmd.hasOption("elasticNetParam")) { value = cmd.getOptionValue("elasticNetParam"); params.elasticNetParam = Double.parseDouble(value); } if (cmd.hasOption("testInput")) { value = cmd.getOptionValue("testInput"); params.testInput = value; } if (cmd.hasOption("fracTest")) { value = cmd.getOptionValue("fracTest"); params.fracTest = Double.parseDouble(value); } } catch (ParseException e) { printHelpAndQuit(options); } return params; }
public static void main(String[] args) { Options options = new Options(); options.addOption("v", true, "Input Vector folder"); // yearly vector data options.addOption("p", true, "Points folder"); // yearly mds (rotate) output options.addOption("d", true, "Destination folder"); options.addOption("o", true, "Original stock file"); // global 10 year stock file options.addOption( "s", true, "Sector file"); // If Histogram true then set this as the folder to histogram output options.addOption("h", false, "Gen from histogram"); options.addOption("e", true, "Extra classes file"); // a file containing fixed classes options.addOption("ci", true, "Cluster input file"); options.addOption("co", true, "Cluster output file"); CommandLineParser commandLineParser = new BasicParser(); try { CommandLine cmd = commandLineParser.parse(options, args); String vectorFile = cmd.getOptionValue("v"); String pointsFolder = cmd.getOptionValue("p"); String distFolder = cmd.getOptionValue("d"); String originalStocks = cmd.getOptionValue("o"); String sectorFile = cmd.getOptionValue("s"); boolean histogram = cmd.hasOption("h"); String fixedClasses = cmd.getOptionValue("e"); String clusterInputFile = cmd.getOptionValue("ci"); String clusterOutputFile = cmd.getOptionValue("co"); LabelApply program = new LabelApply( vectorFile, pointsFolder, distFolder, originalStocks, sectorFile, histogram, fixedClasses, clusterInputFile, clusterOutputFile); program.process(); } catch (ParseException e) { e.printStackTrace(); } }
private void parseCmdLine(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("v", "version", false, "Q2's version"); options.addOption("d", "deploydir", true, "Deployment directory"); options.addOption("r", "recursive", false, "Deploy subdirectories recursively"); options.addOption("h", "help", false, "Usage information"); options.addOption("C", "config", true, "Configuration bundle"); options.addOption("e", "encrypt", true, "Encrypt configuration bundle"); options.addOption("i", "cli", false, "Command Line Interface"); options.addOption("c", "command", true, "Command to execute"); try { CommandLine line = parser.parse(options, args); if (line.hasOption("v")) { displayVersion(); System.exit(0); } if (line.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Q2", options); System.exit(0); } if (line.hasOption("c")) { cli = new CLI(this, line.getOptionValue("c"), line.hasOption("i")); } else if (line.hasOption("i")) cli = new CLI(this, null, true); String dir = DEFAULT_DEPLOY_DIR; if (line.hasOption("d")) { dir = line.getOptionValue("d"); } recursive = line.hasOption("r"); this.deployDir = new File(dir); if (line.hasOption("C")) deployBundle(new File(line.getOptionValue("C")), false); if (line.hasOption("e")) deployBundle(new File(line.getOptionValue("e")), true); } catch (MissingArgumentException e) { System.out.println("ERROR: " + e.getMessage()); System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }