Search in sources :

Example 81 with Options

use of org.apache.commons.cli.Options in project phoenix by apache.

the class AbstractBulkLoadTool method getOptions.

protected Options getOptions() {
    Options options = new Options();
    options.addOption(INPUT_PATH_OPT);
    options.addOption(TABLE_NAME_OPT);
    options.addOption(INDEX_TABLE_NAME_OPT);
    options.addOption(ZK_QUORUM_OPT);
    options.addOption(OUTPUT_PATH_OPT);
    options.addOption(SCHEMA_NAME_OPT);
    options.addOption(IMPORT_COLUMNS_OPT);
    options.addOption(IGNORE_ERRORS_OPT);
    options.addOption(HELP_OPT);
    return options;
}
Also used : Options(org.apache.commons.cli.Options)

Example 82 with Options

use of org.apache.commons.cli.Options in project lucene-solr by apache.

the class SolrSnapshotsTool method main.

public static void main(String[] args) throws IOException {
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption(null, CREATE, true, "This command will create a snapshot with the specified name");
    options.addOption(null, DELETE, true, "This command will delete a snapshot with the specified name");
    options.addOption(null, LIST, false, "This command will list all the named snapshots for the specified collection.");
    options.addOption(null, DESCRIBE, true, "This command will print details for a named snapshot for the specified collection.");
    options.addOption(null, PREPARE_FOR_EXPORT, true, "This command will prepare copylistings for the specified snapshot." + " This command should only be used only if Solr is deployed with Hadoop and collection index files are stored on a shared" + " file-system e.g. HDFS");
    options.addOption(null, EXPORT_SNAPSHOT, true, "This command will create a backup for the specified snapshot.");
    options.addOption(null, HELP, false, "This command will print the help message for the snapshots related commands.");
    options.addOption(TEMP_DIR, true, "This parameter specifies the path of a temporary directory on local filesystem" + " during prepare-snapshot-export command.");
    options.addOption(DEST_DIR, true, "This parameter specifies the path on shared file-system (e.g. HDFS) where the snapshot related" + " information should be stored.");
    options.addOption(COLLECTION, true, "This parameter specifies the name of the collection to be used during snapshot operation");
    options.addOption(SOLR_ZK_ENSEMBLE, true, "This parameter specifies the Solr Zookeeper ensemble address");
    options.addOption(HDFS_PATH_PREFIX, true, "This parameter specifies the HDFS URI prefix to be used" + " during snapshot export preparation. This is applicable only if the Solr collection index files are stored on HDFS.");
    options.addOption(BACKUP_REPO_NAME, true, "This parameter specifies the name of the backup repository to be used" + " during snapshot export preparation");
    options.addOption(ASYNC_REQ_ID, true, "This parameter specifies the async request identifier to be used" + " during snapshot export preparation");
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getLocalizedMessage());
        printHelp(options);
        System.exit(1);
    }
    if (cmd.hasOption(CREATE) || cmd.hasOption(DELETE) || cmd.hasOption(LIST) || cmd.hasOption(DESCRIBE) || cmd.hasOption(PREPARE_FOR_EXPORT) || cmd.hasOption(EXPORT_SNAPSHOT)) {
        try (SolrSnapshotsTool tool = new SolrSnapshotsTool(requiredArg(options, cmd, SOLR_ZK_ENSEMBLE))) {
            if (cmd.hasOption(CREATE)) {
                String snapshotName = cmd.getOptionValue(CREATE);
                String collectionName = requiredArg(options, cmd, COLLECTION);
                tool.createSnapshot(collectionName, snapshotName);
            } else if (cmd.hasOption(DELETE)) {
                String snapshotName = cmd.getOptionValue(DELETE);
                String collectionName = requiredArg(options, cmd, COLLECTION);
                tool.deleteSnapshot(collectionName, snapshotName);
            } else if (cmd.hasOption(LIST)) {
                String collectionName = requiredArg(options, cmd, COLLECTION);
                tool.listSnapshots(collectionName);
            } else if (cmd.hasOption(DESCRIBE)) {
                String snapshotName = cmd.getOptionValue(DESCRIBE);
                String collectionName = requiredArg(options, cmd, COLLECTION);
                tool.describeSnapshot(collectionName, snapshotName);
            } else if (cmd.hasOption(PREPARE_FOR_EXPORT)) {
                String snapshotName = cmd.getOptionValue(PREPARE_FOR_EXPORT);
                String collectionName = requiredArg(options, cmd, COLLECTION);
                String localFsDir = requiredArg(options, cmd, TEMP_DIR);
                String hdfsOpDir = requiredArg(options, cmd, DEST_DIR);
                Optional<String> pathPrefix = Optional.ofNullable(cmd.getOptionValue(HDFS_PATH_PREFIX));
                if (pathPrefix.isPresent()) {
                    try {
                        new URI(pathPrefix.get());
                    } catch (URISyntaxException e) {
                        System.out.println("The specified File system path prefix " + pathPrefix.get() + " is invalid. The error is " + e.getLocalizedMessage());
                        System.exit(1);
                    }
                }
                tool.prepareForExport(collectionName, snapshotName, localFsDir, pathPrefix, hdfsOpDir);
            } else if (cmd.hasOption(EXPORT_SNAPSHOT)) {
                String snapshotName = cmd.getOptionValue(EXPORT_SNAPSHOT);
                String collectionName = requiredArg(options, cmd, COLLECTION);
                String destDir = requiredArg(options, cmd, DEST_DIR);
                Optional<String> backupRepo = Optional.ofNullable(cmd.getOptionValue(BACKUP_REPO_NAME));
                Optional<String> asyncReqId = Optional.ofNullable(cmd.getOptionValue(ASYNC_REQ_ID));
                tool.exportSnapshot(collectionName, snapshotName, destDir, backupRepo, asyncReqId);
            }
        }
    } else if (cmd.hasOption(HELP)) {
        printHelp(options);
    } else {
        System.out.println("Unknown command specified.");
        printHelp(options);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) Optional(java.util.Optional) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 83 with Options

use of org.apache.commons.cli.Options in project phoenix by apache.

the class PhoenixConsumerTool method getOptions.

public static Options getOptions() {
    Options options = new Options();
    options.addOption(FILE_PATH_OPT);
    options.addOption(HELP_OPT);
    return options;
}
Also used : Options(org.apache.commons.cli.Options)

Example 84 with Options

use of org.apache.commons.cli.Options in project asterixdb by apache.

the class AsterixApplicationMaster method setArgs.

public CommandLine setArgs(String[] args) throws ParseException {
    Options opts = new Options();
    opts.addOption("app_attempt_id", true, "App Attempt ID. Not to be used unless for testing purposes");
    opts.addOption("priority", true, "Application Priority. Default 0");
    opts.addOption("debug", false, "Dump out debug information");
    opts.addOption("help", false, "Print usage");
    opts.addOption("initial", false, "Initialize existing Asterix instance.");
    opts.addOption("obliterate", false, "Delete asterix instance completely.");
    opts.addOption("backup", false, "Back up AsterixDB instance");
    opts.addOption("restore", true, "Restore an AsterixDB instance");
    CommandLine cliParser = new GnuParser().parse(opts, args);
    if (cliParser.hasOption("help")) {
        printUsage(opts);
    }
    if (cliParser.hasOption("debug")) {
        dumpOutDebugInfo();
    }
    if (cliParser.hasOption("obliterate")) {
        obliterate = true;
    }
    if (cliParser.hasOption("initial")) {
        initial = true;
    }
    if (cliParser.hasOption("backup")) {
        backup = true;
        backupTimestamp = System.currentTimeMillis();
    }
    if (cliParser.hasOption("restore")) {
        restore = true;
        snapName = cliParser.getOptionValue("restore");
        LOG.info(snapName);
    }
    return cliParser;
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser)

Example 85 with Options

use of org.apache.commons.cli.Options in project solo by b3log.

the class Starter method main.

/**
     * Main.
     *
     * @param args the specified arguments
     * @throws java.lang.Exception if start failed
     */
public static void main(final String[] args) throws Exception {
    final Logger logger = Logger.getLogger(Starter.class);
    final Options options = new Options();
    final Option listenPortOpt = Option.builder("lp").longOpt("listen_port").argName("LISTEN_PORT").hasArg().desc("listen port, default is 8080").build();
    options.addOption(listenPortOpt);
    final Option serverSchemeOpt = Option.builder("ss").longOpt("server_scheme").argName("SERVER_SCHEME").hasArg().desc("browser visit protocol, default is http").build();
    options.addOption(serverSchemeOpt);
    final Option serverHostOpt = Option.builder("sh").longOpt("server_host").argName("SERVER_HOST").hasArg().desc("browser visit domain name, default is localhost").build();
    options.addOption(serverHostOpt);
    final Option serverPortOpt = Option.builder("sp").longOpt("server_port").argName("SERVER_PORT").hasArg().desc("browser visit port, default is 8080").build();
    options.addOption(serverPortOpt);
    final Option staticServerSchemeOpt = Option.builder("sss").longOpt("static_server_scheme").argName("STATIC_SERVER_SCHEME").hasArg().desc("browser visit static resource protocol, default is http").build();
    options.addOption(staticServerSchemeOpt);
    final Option staticServerHostOpt = Option.builder("ssh").longOpt("static_server_host").argName("STATIC_SERVER_HOST").hasArg().desc("browser visit static resource domain name, default is localhost").build();
    options.addOption(staticServerHostOpt);
    final Option staticServerPortOpt = Option.builder("ssp").longOpt("static_server_port").argName("STATIC_SERVER_PORT").hasArg().desc("browser visit static resource port, default is 8080").build();
    options.addOption(staticServerPortOpt);
    final Option runtimeModeOpt = Option.builder("rm").longOpt("runtime_mode").argName("RUNTIME_MODE").hasArg().desc("runtime mode (DEVELOPMENT/PRODUCTION), default is DEVELOPMENT").build();
    options.addOption(runtimeModeOpt);
    options.addOption("h", "help", false, "print help for the command");
    final HelpFormatter helpFormatter = new HelpFormatter();
    final CommandLineParser commandLineParser = new DefaultParser();
    CommandLine commandLine;
    final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
    final String cmdSyntax = isWindows ? "java -cp WEB-INF/lib/*;WEB-INF/classes org.b3log.solo.Starter" : "java -cp WEB-INF/lib/*:WEB-INF/classes org.b3log.solo.Starter";
    final String header = "\nSolo is a blogging system written in Java, feel free to create your or your team own blog.\nSolo 是一个用 Java 实现的博客系统,为你或你的团队创建个博客吧。\n\n";
    final String footer = "\nReport bugs or request features please visit our project website: https://github.com/b3log/solo\n\n";
    try {
        commandLine = commandLineParser.parse(options, args);
    } catch (final ParseException e) {
        helpFormatter.printHelp(cmdSyntax, header, options, footer, true);
        return;
    }
    if (commandLine.hasOption("h")) {
        helpFormatter.printHelp(cmdSyntax, header, options, footer, true);
        return;
    }
    String portArg = commandLine.getOptionValue("listen_port");
    if (!Strings.isNumeric(portArg)) {
        portArg = "8080";
    }
    String serverScheme = commandLine.getOptionValue("server_scheme");
    Latkes.setServerScheme(serverScheme);
    String serverHost = commandLine.getOptionValue("server_host");
    Latkes.setServerHost(serverHost);
    String serverPort = commandLine.getOptionValue("server_port");
    Latkes.setServerPort(serverPort);
    String staticServerScheme = commandLine.getOptionValue("static_server_scheme");
    Latkes.setStaticServerScheme(staticServerScheme);
    String staticServerHost = commandLine.getOptionValue("static_server_host");
    Latkes.setStaticServerHost(staticServerHost);
    String staticServerPort = commandLine.getOptionValue("static_server_port");
    Latkes.setStaticServerPort(staticServerPort);
    String runtimeMode = commandLine.getOptionValue("runtime_mode");
    if (null != runtimeMode) {
        Latkes.setRuntimeMode(RuntimeMode.valueOf(runtimeMode));
    }
    // For Latke IoC 
    Latkes.setScanPath("org.b3log.solo");
    logger.info("Standalone mode, see [https://github.com/b3log/solo/wiki/standalone_mode] for more details.");
    Latkes.initRuntimeEnv();
    // POM structure in dev env
    String webappDirLocation = "src/main/webapp/";
    final File file = new File(webappDirLocation);
    if (!file.exists()) {
        // production environment
        webappDirLocation = ".";
    }
    final int port = Integer.valueOf(portArg);
    final Server server = new Server(port);
    final WebAppContext root = new WebAppContext();
    // Use parent class loader
    root.setParentLoaderPriority(true);
    root.setContextPath("/");
    root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
    root.setResourceBase(webappDirLocation);
    server.setHandler(root);
    try {
        server.start();
    } catch (final Exception e) {
        logger.log(Level.ERROR, "Server start failed", e);
        System.exit(-1);
    }
    serverScheme = Latkes.getServerScheme();
    serverHost = Latkes.getServerHost();
    serverPort = Latkes.getServerPort();
    final String contextPath = Latkes.getContextPath();
    try {
        Desktop.getDesktop().browse(new URI(serverScheme + "://" + serverHost + ":" + serverPort + contextPath));
    } catch (final Throwable e) {
    // Ignored
    }
    server.join();
}
Also used : Options(org.apache.commons.cli.Options) Server(org.eclipse.jetty.server.Server) Logger(org.b3log.latke.logging.Logger) URI(java.net.URI) ParseException(org.apache.commons.cli.ParseException) HelpFormatter(org.apache.commons.cli.HelpFormatter) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

Options (org.apache.commons.cli.Options)1086 CommandLine (org.apache.commons.cli.CommandLine)557 CommandLineParser (org.apache.commons.cli.CommandLineParser)382 ParseException (org.apache.commons.cli.ParseException)341 Option (org.apache.commons.cli.Option)325 HelpFormatter (org.apache.commons.cli.HelpFormatter)275 GnuParser (org.apache.commons.cli.GnuParser)207 DefaultParser (org.apache.commons.cli.DefaultParser)166 Test (org.junit.Test)148 PosixParser (org.apache.commons.cli.PosixParser)135 IOException (java.io.IOException)118 File (java.io.File)97 OptionGroup (org.apache.commons.cli.OptionGroup)56 DMLScript (org.apache.sysml.api.DMLScript)56 Path (org.apache.hadoop.fs.Path)54 ArrayList (java.util.ArrayList)38 BasicParser (org.apache.commons.cli.BasicParser)36 Properties (java.util.Properties)33 Configuration (org.apache.hadoop.conf.Configuration)31 FileInputStream (java.io.FileInputStream)29