Example usage for org.apache.commons.cli OptionBuilder withLongOpt

List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder withLongOpt.

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:net.timbusproject.extractors.debiansoftwareextractor.CLI.java

@SuppressWarnings("static-access")
public CLI() {/*w ww  . j  ava  2 s.  c  o  m*/
    addOptions(OptionBuilder.withLongOpt("help").withDescription("Shows help").create('h'),
            createOptionGroup(
                    OptionBuilder.withLongOpt("local").withDescription("Extracts locally").create('l'),
                    OptionBuilder.withLongOpt("remote").withDescription("Extracts remotely").hasArgs()
                            .withArgName("user@host:port").create('r')),
            OptionBuilder.withLongOpt("universe").withDescription("Extracts universe").create('u'),
            OptionBuilder.withLongOpt("output").withDescription("Outputs results to file").hasArg()
                    .withArgName("file").withType(File.class).create('o'),
            OptionBuilder.withLongOpt("pretty").withDescription("Returns a formatted result").create('p'),
            createOptionGroup(
                    OptionBuilder.withLongOpt("debug").withDescription("Provides more details").create(),
                    OptionBuilder.withLongOpt("quiet").withDescription("Provides less details").create('q')));
}

From source file:net.timbusproject.extractors.rpmsoftwareextractor.CLI.java

@SuppressWarnings("static-access")
public CLI() {//from  www .  j a v a  2  s  .  co m
    addOptions(OptionBuilder.withLongOpt("help").withDescription("Shows help").create('h'),
            createOptionGroup(
                    OptionBuilder.withLongOpt("local").withDescription("Extracts locally").create('l'),
                    OptionBuilder.withLongOpt("remote").withDescription("Extracts remotely").hasArgs()
                            .withArgName("user@host:port").create('r')),
            //                OptionBuilder.withLongOpt("universe").withDescription("Extracts universe").create('u'),
            OptionBuilder.withLongOpt("output").withDescription("Outputs results to file").hasArg()
                    .withArgName("file").withType(File.class).create('o'),
            OptionBuilder.withLongOpt("pretty").withDescription("Returns a formatted result").create('p'),
            createOptionGroup(
                    OptionBuilder.withLongOpt("debug").withDescription("Provides more details").create(),
                    OptionBuilder.withLongOpt("quiet").withDescription("Provides less details").create('q')));
}

From source file:net.vhati.modmanager.cli.SlipstreamCLI.java

public static void main(String[] args) {

    BasicParser parser = new BasicParser();

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("extract-dats")
            .withDescription("extract FTL resources into a dir").hasArg().withArgName("DIR").create());
    options.addOption(OptionBuilder.withLongOpt("global-panic")
            .withDescription("patch as if advanced find tags had panic='true'").create());
    options.addOption(/*from  w w  w . j  a  va 2s .co  m*/
            OptionBuilder.withLongOpt("list-mods").withDescription("list available mod names").create());
    options.addOption(OptionBuilder.withLongOpt("runftl")
            .withDescription("run the game (standalone or with 'patch')").create());
    options.addOption(OptionBuilder.withLongOpt("patch")
            .withDescription("revert to vanilla and add named mods (if any)").create());
    options.addOption(
            OptionBuilder.withLongOpt("validate").withDescription("check named mods for problems").create());
    options.addOption("h", "help", false, "display this help and exit");
    options.addOption(OptionBuilder.withLongOpt("version")
            .withDescription("output version information and exit").create());
    CommandLine cmdline = null;
    try {
        cmdline = parser.parse(options, args, true);
    } catch (ParseException e) {
        System.err.println("Error parsing commandline: " + e.getMessage());
        System.exit(1);
    }

    if (cmdline.hasOption("h")) { // Exits.
        HelpFormatter formatter = new HelpFormatter();

        String helpHeader = "Perform actions against an FTL installation and/or a list of named mods."
                + formatter.getNewLine();

        String helpFooter = formatter.getNewLine();
        helpFooter += "Each MODFILE is a filename in the mods/ dir." + formatter.getNewLine();
        helpFooter += "If a named mod is a directory, a temporary zip will be created.";

        formatter.printHelp("modman [OPTION] [MODFILE]...", helpHeader, options, helpFooter);
        System.exit(0);
    }
    if (cmdline.hasOption("version")) { // Exits.
        System.out.println(getVersionMessage());
        System.exit(0);
    }

    DelayedDeleteHook deleteHook = new DelayedDeleteHook();
    Runtime.getRuntime().addShutdownHook(deleteHook);

    if (cmdline.hasOption("validate")) { // Exits (0/1).
        log.info("Validating...");

        StringBuilder resultBuf = new StringBuilder();
        ReportFormatter formatter = new ReportFormatter();
        boolean anyInvalid = false;

        for (String modFileName : cmdline.getArgs()) {
            File modFile = new File(modsDir, modFileName);

            if (modFile.isDirectory()) {
                log.info(String.format("Zipping dir: %s/", modFile.getName()));
                try {
                    modFile = createTempMod(modFile);
                    deleteHook.addDoomedFile(modFile);
                } catch (IOException e) {
                    log.error(String.format("Error zipping \"%s/\".", modFile.getName()), e);

                    List<ReportMessage> tmpMessages = new ArrayList<ReportMessage>();
                    tmpMessages.add(new ReportMessage(ReportMessage.SECTION, modFileName));
                    tmpMessages.add(new ReportMessage(ReportMessage.EXCEPTION, e.getMessage()));

                    formatter.format(tmpMessages, resultBuf, 0);
                    resultBuf.append("\n");

                    anyInvalid = true;
                    continue;
                }
            }

            Report validateReport = ModUtilities.validateModFile(modFile);

            formatter.format(validateReport.messages, resultBuf, 0);
            resultBuf.append("\n");

            if (validateReport.outcome == false)
                anyInvalid = true;
        }
        if (resultBuf.length() == 0) {
            resultBuf.append("No mods were checked.");
        }

        System.out.println();
        System.out.println(resultBuf.toString());
        System.exit(anyInvalid ? 1 : 0);
    }

    File configFile = new File("modman.cfg");
    Properties config = getConfig(configFile);

    if (cmdline.hasOption("list-mods")) { // Exits.
        log.info("Listing mods...");

        boolean allowZip = config.getProperty("allow_zip", "false").equals("true");
        File[] modFiles = modsDir.listFiles(new ModAndDirFileFilter(allowZip, true));
        List<String> dirList = new ArrayList<String>();
        List<String> fileList = new ArrayList<String>();
        for (File f : modFiles) {
            if (f.isDirectory())
                dirList.add(f.getName() + "/");
            else
                fileList.add(f.getName());
        }
        Collections.sort(dirList);
        Collections.sort(fileList);
        for (String s : dirList)
            System.out.println(s);
        for (String s : fileList)
            System.out.println(s);

        System.exit(0);
    }

    File datsDir = null;
    if (cmdline.hasOption("extract-dats") || cmdline.hasOption("patch") || cmdline.hasOption("runftl")) {
        datsDir = getDatsDir(config);
    }

    if (cmdline.hasOption("extract-dats")) { // Exits (0/1).
        log.info("Extracting dats...");

        String extractPath = cmdline.getOptionValue("extract-dats");
        File extractDir = new File(extractPath);

        File dataDatFile = new File(datsDir, "data.dat");
        File resDatFile = new File(datsDir, "resource.dat");
        File[] datFiles = new File[] { dataDatFile, resDatFile };

        FTLDat.AbstractPack srcP = null;
        FTLDat.AbstractPack dstP = null;
        InputStream is = null;
        try {
            if (!extractDir.exists())
                extractDir.mkdirs();

            dstP = new FTLDat.FolderPack(extractDir);

            for (File datFile : datFiles) {
                srcP = new FTLDat.FTLPack(datFile, "r");
                List<String> innerPaths = srcP.list();

                for (String innerPath : innerPaths) {
                    if (dstP.contains(innerPath)) {
                        log.info("While extracting resources, this file was overwritten: " + innerPath);
                        dstP.remove(innerPath);
                    }
                    is = srcP.getInputStream(innerPath);
                    dstP.add(innerPath, is);
                }
                srcP.close();
            }
        } catch (IOException e) {
            log.error("Error extracting dats.", e);
            System.exit(1);
        } finally {
            try {
                if (is != null)
                    is.close();
            } catch (IOException ex) {
            }

            try {
                if (srcP != null)
                    srcP.close();
            } catch (IOException ex) {
            }

            try {
                if (dstP != null)
                    dstP.close();
            } catch (IOException ex) {
            }
        }

        System.exit(0);
    }

    if (cmdline.hasOption("patch")) { // Exits sometimes (1 on failure).
        log.info("Patching...");

        List<File> modFiles = new ArrayList<File>();
        for (String modFileName : cmdline.getArgs()) {
            File modFile = new File(modsDir, modFileName);

            if (modFile.isDirectory()) {
                log.info(String.format("Zipping dir: %s/", modFile.getName()));
                try {
                    modFile = createTempMod(modFile);
                    deleteHook.addDoomedFile(modFile);
                } catch (IOException e) {
                    log.error(String.format("Error zipping \"%s/\".", modFile.getName()), e);
                    System.exit(1);
                }
            }

            modFiles.add(modFile);
        }

        BackedUpDat dataDat = new BackedUpDat();
        dataDat.datFile = new File(datsDir, "data.dat");
        dataDat.bakFile = new File(backupDir, "data.dat.bak");
        BackedUpDat resDat = new BackedUpDat();
        resDat.datFile = new File(datsDir, "resource.dat");
        resDat.bakFile = new File(backupDir, "resource.dat.bak");

        boolean globalPanic = cmdline.hasOption("global-panic");

        SilentPatchObserver patchObserver = new SilentPatchObserver();
        ModPatchThread patchThread = new ModPatchThread(modFiles, dataDat, resDat, globalPanic, patchObserver);
        deleteHook.addWatchedThread(patchThread);

        patchThread.start();
        while (patchThread.isAlive()) {
            try {
                patchThread.join();
            } catch (InterruptedException e) {
            }
        }

        if (!patchObserver.hasSucceeded())
            System.exit(1);
    }

    if (cmdline.hasOption("runftl")) { // Exits (0/1).
        log.info("Running FTL...");

        File exeFile = FTLUtilities.findGameExe(datsDir);
        if (exeFile != null) {
            try {
                FTLUtilities.launchGame(exeFile);
            } catch (Exception e) {
                log.error("Error launching FTL.", e);
                System.exit(1);
            }
        } else {
            log.error("Could not find FTL's executable.");
            System.exit(1);
        }

        System.exit(0);
    }

    System.exit(0);
}

From source file:nl.strohalm.cyclos.setup.Arguments.java

static Options buildOptions(final Locale locale) {
    final ResourceBundle bundle = Setup.getResourceBundle(locale);
    final Options options = new Options();

    // help/*from   w w w. j  ava  2  s  .c om*/
    OptionBuilder.withLongOpt("help");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(bundle.getString("arg.help"));
    options.addOption(OptionBuilder.create('?'));

    // force
    OptionBuilder.withLongOpt("force");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(bundle.getString("arg.force"));
    options.addOption(OptionBuilder.create('f'));

    // create database
    OptionBuilder.withLongOpt("database");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(bundle.getString("arg.create-data-base"));
    options.addOption(OptionBuilder.create('d'));

    // export script
    OptionBuilder.withLongOpt("script");
    OptionBuilder.hasOptionalArg();
    OptionBuilder.withArgName("file");
    OptionBuilder.withDescription(bundle.getString("arg.export-script"));
    options.addOption(OptionBuilder.create('s'));

    // create basic data
    OptionBuilder.withLongOpt("basic-data");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(bundle.getString("arg.create-basic-data"));
    options.addOption(OptionBuilder.create('b'));

    // create initial data
    OptionBuilder.withLongOpt("initial-data");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(bundle.getString("arg.create-initial-data"));
    options.addOption(OptionBuilder.create('i'));

    // create sms data
    OptionBuilder.withLongOpt("sms-data");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(bundle.getString("arg.create-sms-data"));
    options.addOption(OptionBuilder.create('m'));

    return options;
}

From source file:nl.vumc.trait.oc.main.CleanODM.java

@SuppressWarnings("static-access")
@Override/*from  w  w w  .  j  a v  a2  s .c  om*/
protected void setupOptions() {
    // create the Options
    options.addOption(OptionBuilder.withLongOpt("base-url")
            .withDescription("OpenClinica base URL (i.e. https://www.example.org/OpenClinica-ws/)").hasArg()
            .withArgName("URL").isRequired(true).create("b"));
    options.addOption(OptionBuilder.withLongOpt("user").withDescription("OpenClinica username").hasArg()
            .withArgName("username").isRequired(true).create("u"));
    options.addOption(OptionBuilder.withLongOpt("password").withDescription("OpenClinica password").hasArg()
            .withArgName("password").isRequired(true).create("p"));
    options.addOption(OptionBuilder.withLongOpt("file")
            .withDescription("XML file containing the ClinicalData. A hyphen (-) means stdin.").hasArg()
            .withArgName("file").isRequired(true).create("f"));
    options.addOption("r", "resolve", false,
            "Resolve ODM. This includes potentially creating subjects and scheduling events.");
    options.addOption("h", "help", false, "this help screen");
    options.addOption("v", "verbose", false, "be (very) verbose");
}

From source file:nl.vumc.trait.oc.main.ExtractODM.java

@SuppressWarnings("static-access")
@Override/*from w  ww  .j a  va 2s .  c o  m*/
protected void setupOptions() {
    // create the Options
    options.addOption(OptionBuilder.withLongOpt("base-url")
            .withDescription("OpenClinica base URL (i.e. https://www.example.org/OpenClinica-ws/)").hasArg()
            .withArgName("URL").isRequired(true).create("b"));
    options.addOption(OptionBuilder.withLongOpt("user").withDescription("OpenClinica username").hasArg()
            .withArgName("username").isRequired(true).create("u"));
    options.addOption(OptionBuilder.withLongOpt("password").withDescription("OpenClinica password").hasArg()
            .withArgName("password").isRequired(true).create("p"));
    options.addOption(OptionBuilder.withLongOpt("study")
            .withDescription("OpenClinica study name (or site unique identifier)").hasArg().withArgName("study")
            .isRequired(true).create("s"));
    options.addOption("m", "meta", false, "get plain metadata (do not translate to template)");
    options.addOption("h", "help", false, "this help screen");
    options.addOption("v", "verbose", false, "be (very) verbose");
}

From source file:nl.vumc.trait.oc.main.ImportODM.java

@SuppressWarnings("static-access")
@Override//from  w ww .  ja va  2 s.  com
protected void setupOptions() {
    // create the Options
    options.addOption(OptionBuilder.withLongOpt("base-url")
            .withDescription("OpenClinica base URL (i.e. https://www.example.org/OpenClinica-ws/)").hasArg()
            .withArgName("URL").isRequired(true).create("b"));
    options.addOption(OptionBuilder.withLongOpt("user").withDescription("OpenClinica username").hasArg()
            .withArgName("username").isRequired(true).create("u"));
    options.addOption(OptionBuilder.withLongOpt("password").withDescription("OpenClinica password").hasArg()
            .withArgName("password").isRequired(true).create("p"));
    options.addOption(OptionBuilder.withLongOpt("file")
            .withDescription("XML file containing the ClinicalData. A hyphen (-) means stdin.").hasArg()
            .withArgName("file").isRequired(true).create("f"));
    options.addOption("h", "help", false, "this help screen");
    options.addOption("v", "verbose", false, "be (very) verbose");
}

From source file:nl.vumc.trait.oc.main.ListStudies.java

@SuppressWarnings("static-access")
@Override/*w w w.j  av  a  2s.  c om*/
protected void setupOptions() {
    // create the Options
    options.addOption(OptionBuilder.withLongOpt("base-url")
            .withDescription("OpenClinica base URL (i.e. https://www.example.org/OpenClinica-ws/)").hasArg()
            .withArgName("URL").isRequired(true).create("b"));
    options.addOption(OptionBuilder.withLongOpt("user").withDescription("OpenClinica username").hasArg()
            .withArgName("username").isRequired(true).create("u"));
    options.addOption(OptionBuilder.withLongOpt("password").withDescription("OpenClinica password").hasArg()
            .withArgName("password").isRequired(true).create("p"));
    options.addOption("h", "help", false, "this help screen");
    options.addOption("v", "verbose", false, "be (very) verbose");
}

From source file:nl.vumc.trait.oc.main.ListSubjects.java

@SuppressWarnings("static-access")
@Override//from w  ww  .  j  a  va2s.c om
protected void setupOptions() {
    // create the Options
    options.addOption(OptionBuilder.withLongOpt("base-url")
            .withDescription("OpenClinica base URL (i.e. https://www.example.org/OpenClinica-ws/)").hasArg()
            .withArgName("URL").isRequired(true).create("b"));
    options.addOption(OptionBuilder.withLongOpt("user").withDescription("OpenClinica username").hasArg()
            .withArgName("username").isRequired(true).create("u"));
    options.addOption(OptionBuilder.withLongOpt("password").withDescription("OpenClinica password").hasArg()
            .withArgName("password").isRequired(true).create("p"));
    options.addOption(OptionBuilder.withLongOpt("study")
            .withDescription("OpenClinica study name (or site unique identifier)").hasArg().withArgName("study")
            .isRequired(true).create("s"));
    options.addOption("h", "help", false, "this help screen");
    options.addOption("v", "verbose", false, "be (very) verbose");
}

From source file:norbert.mynemo.ui.ImportCommandParser.java

private static Options getOptions() {
    OptionBuilder.isRequired();//w  ww . j  a  va  2  s.  co m
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(OUT_ARG_NAME);
    OptionBuilder.withDescription(OUT_DESCRIPTION);
    OptionBuilder.withLongOpt(OUT_LONG_OPTION);
    Option out = OptionBuilder.create(OUT_CHAR_OPTION);

    OptionBuilder.isRequired();
    OptionBuilder.hasArgs();
    OptionBuilder.withArgName(RATINGS_ARG_NAME);
    OptionBuilder.withLongOpt(RATINGS_LONG_OPTION);
    OptionBuilder.withDescription(RATINGS_DESCRIPTION);
    Option ratings = OptionBuilder.create(RATINGS_CHAR_OPTION);

    OptionBuilder.hasArg();
    OptionBuilder.withArgName(MOVIES_ARG_NAME);
    OptionBuilder.withLongOpt(MOVIES_LONG_OPTION);
    OptionBuilder.withDescription(MOVIES_DESCRIPTION);
    Option movies = OptionBuilder.create(MOVIES_CHAR_OPTION);

    OptionBuilder.hasArg();
    OptionBuilder.withArgName(USER_ARG_NAME);
    OptionBuilder.withLongOpt(USER_LONG_OPTION);
    OptionBuilder.withDescription(USER_DESCRIPTION);
    Option user = OptionBuilder.create(USER_CHAR_OPTION);

    OptionBuilder.hasArg();
    OptionBuilder.withArgName(MAX_USERS_ARG_NAME);
    OptionBuilder.withLongOpt(MAX_USERS_LONG_OPTION);
    OptionBuilder.withDescription(MAX_USERS_DESCRIPTION);
    Option maxUsers = OptionBuilder.create();

    OptionBuilder.hasArg();
    OptionBuilder.withArgName(MIN_RATINGS_BY_MOVIE_ARG_NAME);
    OptionBuilder.withLongOpt(MIN_RATINGS_BY_MOVIE_LONG_OPTION);
    OptionBuilder.withDescription(MIN_RATINGS_BY_MOVIE_DESCRIPTION);
    Option minRatingsByMovie = OptionBuilder.create();

    OptionBuilder.hasArg();
    OptionBuilder.withArgName(MIN_COMMON_RATINGS_ARG_NAME);
    OptionBuilder.withLongOpt(MIN_COMMON_RATINGS_LONG_OPTION);
    OptionBuilder.withDescription(MIN_COMMON_RATINGS_DESCRIPTION);
    Option minCommonRatings = OptionBuilder.create();

    OptionBuilder.hasArg();
    OptionBuilder.withArgName(SIMILARITY_ARG_NAME);
    OptionBuilder.withLongOpt(SIMILARITY_LONG_OPTION);
    OptionBuilder.withDescription(SIMILARITY_DESCRIPTION);
    Option similarity = OptionBuilder.create(SIMILARITY_CHAR_OPTION);

    return new Options().addOption(out).addOption(ratings).addOption(movies).addOption(user).addOption(maxUsers)
            .addOption(minRatingsByMovie).addOption(minCommonRatings).addOption(similarity);
}