List of usage examples for org.apache.commons.cli OptionGroup getSelected
public String getSelected()
From source file:de.unibi.techfak.bibiserv.util.codegen.Main.java
public static void main(String[] args) { // check & validate cmdline options OptionGroup opt_g = getCMDLineOptionsGroups(); Options opt = getCMDLineOptions();//w ww. j a v a2 s. com opt.addOptionGroup(opt_g); CommandLineParser cli = new DefaultParser(); try { CommandLine cl = cli.parse(opt, args); if (cl.hasOption("v")) { VerboseOutputFilter.SHOW_VERBOSE = true; } switch (opt_g.getSelected()) { case "V": try { URL jarUrl = Main.class.getProtectionDomain().getCodeSource().getLocation(); String jarPath = URLDecoder.decode(jarUrl.getFile(), "UTF-8"); JarFile jarFile = new JarFile(jarPath); Manifest m = jarFile.getManifest(); StringBuilder versionInfo = new StringBuilder(); for (Object key : m.getMainAttributes().keySet()) { versionInfo.append(key).append(":").append(m.getMainAttributes().getValue(key.toString())) .append("\n"); } System.out.println(versionInfo.toString()); } catch (Exception e) { log.error("Version info could not be read."); } break; case "h": HelpFormatter help = new HelpFormatter(); String header = ""; //TODO: missing infotext StringBuilder footer = new StringBuilder("Supported configuration properties :"); help.printHelp("CodeGen -h | -V | -g [...]", header, opt, footer.toString()); break; case "g": // target dir if (cl.hasOption("t")) { File target = new File(cl.getOptionValue("t")); if (target.isDirectory() && target.canExecute() && target.canWrite()) { config.setProperty("target.dir", cl.getOptionValue("t")); } else { log.error("Target dir '{}' is inaccessible!", cl.getOptionValue("t")); break; } } else { config.setProperty("target.dir", System.getProperty("java.io.tmpdir")); } // project dir if (cl.hasOption("p")) { File project = new File(cl.getOptionValue("p")); if (!project.exists()) { if (!project.mkdirs()) { log.error("Project dir '{}' can't be created!", cl.getOptionValue("p")); break; } } if (project.isDirectory() && project.canExecute() && project.canWrite()) { config.setProperty("project.dir", cl.getOptionValue("p")); } else { log.error("Project dir '{}' is inaccessible!", cl.getOptionValue("p")); break; } } generateAppfromXML(cl.getOptionValue("g")); break; } } catch (ParseException e) { log.error("ParseException occurred while parsing cmdline arguments!\n{}", e.getLocalizedMessage()); } }
From source file:org.dcm4che.tool.dcmdir.DcmDir.java
@SuppressWarnings("static-access") private static CommandLine parseComandLine(String[] args) throws ParseException { Options opts = new Options(); CLIUtils.addCommonOptions(opts);//from ww w .j a v a 2 s . c o m CLIUtils.addFilesetInfoOptions(opts); OptionGroup cmdGroup = new OptionGroup(); addCommandOptions(cmdGroup); opts.addOptionGroup(cmdGroup); opts.addOption(OptionBuilder.withLongOpt("width").hasArg().withArgName("col") .withDescription(rb.getString("width")).create("w")); opts.addOption(null, "in-use", false, rb.getString("in-use")); opts.addOption(null, "orig-seq-len", false, rb.getString("orig-seq-len")); CLIUtils.addEncodingOptions(opts); CommandLine cl = CLIUtils.parseComandLine(args, opts, rb, DcmDir.class); if (cmdGroup.getSelected() == null) throw new ParseException(rb.getString("missing")); return cl; }
From source file:org.dcm4che3.tool.dcmldap.DcmLdap.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { try {/*from w ww . jav a2 s . c om*/ OptionGroup cmdGroup = new OptionGroup(); CommandLine cl = parseComandLine(args, cmdGroup); Operation op = Operation.valueOf(cmdGroup.getSelected()); try (DcmLdap main = new DcmLdap(ldapEnv(cl))) { op.configure(main, cl); op.perform(main); } } catch (ParseException e) { System.err.println("dcmldap: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } }
From source file:org.dcm4che3.tool.dcmldap.DcmLdap.java
@SuppressWarnings("static-access") private static CommandLine parseComandLine(String[] args, OptionGroup cmdGroup) throws ParseException { Options opts = new Options(); CLIUtils.addCommonOptions(opts);//from w w w . j av a 2s.c om cmdGroup.addOption(OptionBuilder.hasArg().withArgName("aet@host:port") .withDescription(rb.getString("create")).create("c")); cmdGroup.addOption(OptionBuilder.hasArg().withArgName("aet@host:port").withDescription(rb.getString("add")) .create("a")); cmdGroup.addOption( OptionBuilder.hasArg().withArgName("aet").withDescription(rb.getString("delete")).create("d")); opts.addOptionGroup(cmdGroup); opts.addOption( OptionBuilder.hasArg().withArgName("ldapuri").withDescription(rb.getString("ldapuri")).create("H")); opts.addOption( OptionBuilder.hasArg().withArgName("binddn").withDescription(rb.getString("binddn")).create("D")); opts.addOption( OptionBuilder.hasArg().withArgName("passwd").withDescription(rb.getString("passwd")).create("w")); opts.addOption(OptionBuilder.withLongOpt("dev").hasArg().withArgName("name") .withDescription(rb.getString("dev")).create(null)); opts.addOption(OptionBuilder.withLongOpt("dev-desc").hasArg().withArgName("string") .withDescription(rb.getString("dev-desc")).create(null)); opts.addOption(OptionBuilder.withLongOpt("dev-type").hasArg().withArgName("string") .withDescription(rb.getString("dev-type")).create(null)); opts.addOption(OptionBuilder.withLongOpt("ae-desc").hasArg().withArgName("string") .withDescription(rb.getString("ae-desc")).create(null)); opts.addOption(OptionBuilder.withLongOpt("conn").hasArg().withArgName("cn") .withDescription(rb.getString("conn-cn")).create(null)); CLIUtils.addTLSCipherOptions(opts); CommandLine cl = CLIUtils.parseComandLine(args, opts, rb, DcmLdap.class); String selected = cmdGroup.getSelected(); if (selected == null) throw new ParseException(rb.getString("missing")); if (selected.equals("a") && !cl.hasOption("dev")) throw new ParseException(rb.getString("missing-dev")); return cl; }
From source file:org.dspace.eperson.Groomer.java
/** * Command line tool for "grooming" the EPerson collection. *///from w w w.j ava 2s. c om static public void main(String[] argv) throws SQLException { final String USAGE = "EPerson -verb [option...]"; OptionGroup verbs = new OptionGroup(); verbs.setRequired(true); verbs.addOption(new Option("h", "help", false, "explain this tool")); verbs.addOption(new Option("u", "unsalted", false, "list accounts with unsalted password hashes")); Options options = new Options(); options.addOptionGroup(verbs); PosixParser parser = new PosixParser(); CommandLine command = null; try { command = parser.parse(options, argv); } catch (ParseException ex) { System.err.println(ex.getMessage()); if (!(ex instanceof MissingOptionException)) new HelpFormatter().printHelp(USAGE, options); System.exit(1); } // Help the user if (command.hasOption('h') || command.hasOption('?')) { new HelpFormatter().printHelp(USAGE, options); } // Scan for unsalted hashes else if (command.hasOption('u')) { Context myContext = new Context(); final TableRowIterator tri = DatabaseManager.query(myContext, "SELECT email FROM EPerson WHERE password IS NOT NULL AND digest_algorithm IS NULL"); for (TableRow row = tri.next(); tri.hasNext(); row = tri.next()) System.out.println(row.getStringColumn("email")); myContext.abort(); // No changes to commit } // Should not happen: verb option defined but no code! else System.err.println("Unimplemented verb: " + verbs.getSelected()); }
From source file:org.eclipse.rdf4j.console.Console.java
public static void main(final String[] args) throws IOException { final Console console = new Console(); final Option helpOption = new Option("h", "help", false, "print this help"); final Option versionOption = new Option("v", "version", false, "print version information"); final Option serverURLOption = new Option("s", "serverURL", true, "URL of RDF4J Server to connect to, e.g. http://localhost:8080/rdf4j-server/"); final Option dirOption = new Option("d", "dataDir", true, "data dir to 'connect' to"); Option echoOption = new Option("e", "echo", false, "echoes input back to stdout, useful for logging script sessions"); Option quietOption = new Option("q", "quiet", false, "suppresses prompts, useful for scripting"); Option forceOption = new Option("f", "force", false, "always answer yes to (suppressed) confirmation prompts"); Option cautiousOption = new Option("c", "cautious", false, "always answer no to (suppressed) confirmation prompts"); Option exitOnErrorMode = new Option("x", "exitOnError", false, "immediately exit the console on the first error"); final Options options = new Options(); OptionGroup cautionGroup = new OptionGroup().addOption(cautiousOption).addOption(forceOption) .addOption(exitOnErrorMode); OptionGroup locationGroup = new OptionGroup().addOption(serverURLOption).addOption(dirOption); options.addOptionGroup(locationGroup).addOptionGroup(cautionGroup); options.addOption(helpOption).addOption(versionOption).addOption(echoOption).addOption(quietOption); CommandLine commandLine = parseCommandLine(args, console, options); handleInfoOptions(console, helpOption, versionOption, options, commandLine); console.consoleIO.setEcho(commandLine.hasOption(echoOption.getOpt())); console.consoleIO.setQuiet(commandLine.hasOption(quietOption.getOpt())); exitOnError = commandLine.hasOption(exitOnErrorMode.getOpt()); String location = handleOptionGroups(console, serverURLOption, dirOption, forceOption, cautiousOption, options, cautionGroup, locationGroup, commandLine); final String[] otherArgs = commandLine.getArgs(); if (otherArgs.length > 1) { printUsage(console.consoleIO, options); System.exit(1);/* w w w.ja v a 2 s . c om*/ } connectAndOpen(console, locationGroup.getSelected(), location, otherArgs); console.start(); }
From source file:org.openrdf.console.Console.java
public static void main(final String[] args) throws IOException { final Console console = new Console(); final Option helpOption = new Option("h", "help", false, "print this help"); final Option versionOption = new Option("v", "version", false, "print version information"); final Option serverURLOption = new Option("s", "serverURL", true, "URL of Sesame server to connect to, e.g. http://localhost/openrdf-sesame/"); final Option dirOption = new Option("d", "dataDir", true, "Sesame data dir to 'connect' to"); Option echoOption = new Option("e", "echo", false, "echoes input back to stdout, useful for logging script sessions"); Option quietOption = new Option("q", "quiet", false, "suppresses prompts, useful for scripting"); Option forceOption = new Option("f", "force", false, "always answer yes to (suppressed) confirmation prompts"); Option cautiousOption = new Option("c", "cautious", false, "always answer no to (suppressed) confirmation prompts"); Option exitOnErrorMode = new Option("x", "exitOnError", false, "immediately exit the console on the first error"); final Options options = new Options(); OptionGroup cautionGroup = new OptionGroup().addOption(cautiousOption).addOption(forceOption) .addOption(exitOnErrorMode); OptionGroup locationGroup = new OptionGroup().addOption(serverURLOption).addOption(dirOption); options.addOptionGroup(locationGroup).addOptionGroup(cautionGroup); options.addOption(helpOption).addOption(versionOption).addOption(echoOption).addOption(quietOption); CommandLine commandLine = parseCommandLine(args, console, options); handleInfoOptions(console, helpOption, versionOption, options, commandLine); console.consoleIO.setEcho(commandLine.hasOption(echoOption.getOpt())); console.consoleIO.setQuiet(commandLine.hasOption(quietOption.getOpt())); exitOnError = commandLine.hasOption(exitOnErrorMode.getOpt()); String location = handleOptionGroups(console, serverURLOption, dirOption, forceOption, cautiousOption, options, cautionGroup, locationGroup, commandLine); final String[] otherArgs = commandLine.getArgs(); if (otherArgs.length > 1) { printUsage(console.consoleIO, options); System.exit(1);// www.j a va 2 s.c o m } connectAndOpen(console, locationGroup.getSelected(), location, otherArgs); console.start(); }