Example usage for org.apache.commons.cli Option setRequired

List of usage examples for org.apache.commons.cli Option setRequired

Introduction

In this page you can find the example usage for org.apache.commons.cli Option setRequired.

Prototype

public void setRequired(boolean required) 

Source Link

Document

Sets whether this Option is mandatory.

Usage

From source file:com.opengamma.bloombergexample.loader.PortfolioLoaderHelper.java

/**
 * Builds the set of options.//from   ww w .  j  av a  2  s .  c  o m
 * 
 * @param options  the options to add to, not null
 */
public static void buildOptions(Options options) {
    Option filenameOption = new Option(FILE_NAME_OPT, "filename", true,
            "The path to the CSV file of cash details");
    filenameOption.setRequired(true);
    options.addOption(filenameOption);

    Option portfolioNameOption = new Option(PORTFOLIO_NAME_OPT, "name", true, "The name of the portfolio");
    portfolioNameOption.setRequired(true);
    options.addOption(portfolioNameOption);

    //    Option runModeOption = new Option(RUN_MODE_OPT, "runmode", true, "The run mode: shareddev, standalone");
    //    runModeOption.setRequired(true);
    //    options.addOption(runModeOption);

    Option writeOption = new Option(WRITE_OPT, "write", false,
            "Actually persists the portfolio to the database");
    options.addOption(writeOption);
}

From source file:com.alibaba.rocketmq.broker.BrokerStartup.java

public static Options buildCommandlineOptions(final Options options) {
    Option opt = new Option("c", "configFile", true, "Broker config properties file");
    opt.setRequired(false);
    options.addOption(opt);/*w  w  w.  j  a  v  a2 s.  c o m*/

    opt = new Option("p", "printConfigItem", false, "Print all config item");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("m", "printImportantConfig", false, "Print important config item");
    opt.setRequired(false);
    options.addOption(opt);

    return options;
}

From source file:com.twitter.hraven.etl.ProcessingRecordsPrinter.java

/**
 * Parse command-line arguments./*from w ww . j a v a 2s.c  o  m*/
 * 
 * @param args
 *          command line arguments passed to program.
 * @return parsed command line.
 * @throws ParseException
 */
private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = new Options();

    // Input
    Option o = new Option("m", "maxCount", true, "maximum number of records to be returned");
    o.setArgName("maxCount");
    o.setRequired(false);
    options.addOption(o);

    o = new Option("c", "cluster", true, "cluster for which jobs are processed");
    o.setArgName("cluster");
    o.setRequired(true);
    options.addOption(o);

    o = new Option("p", "processFileSubstring", true,
            "use only those process records where the process file path contains the provided string.");
    o.setArgName("processFileSubstring");
    o.setRequired(false);
    options.addOption(o);

    // Debugging
    options.addOption("d", "debug", false, "switch on DEBUG log level");

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println("ERROR: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(NAME + " ", options, true);
        System.exit(-1);
    }

    // Set debug level right away
    if (commandLine.hasOption("d")) {
        Logger log = Logger.getLogger(ProcessingRecordsPrinter.class);
        log.setLevel(Level.DEBUG);
    }

    return commandLine;
}

From source file:com.blackducksoftware.tools.notifiers.jira.JiraIntegrationUtility.java

static int process(String[] args) {
    System.out.println("Jira Integration for Black Duck Suite");
    CommandLineParser parser = new DefaultParser();

    options.addOption("h", "help", false, "show help.");

    Option protexProjectNameOption = new Option(NotifierConstants.CL_PROTEX_PROJECT_NAME, true,
            "Name of Project (required)");
    protexProjectNameOption.setRequired(true);
    options.addOption(protexProjectNameOption);

    Option projectAliasOption = new Option(NotifierConstants.CL_JIRA_PROJECT_NAME, true,
            "Name of JIRA Project (optional)");
    projectAliasOption.setRequired(false);
    options.addOption(projectAliasOption);

    Option configFileOption = new Option("config", true, "Location of configuration file (required)");
    configFileOption.setRequired(true);//from  w w  w  .j  a va2s .  c om
    options.addOption(configFileOption);

    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            help();
            return 0;
        }

        String projectName = null;
        File configFile = null;
        if (cmd.hasOption(NotifierConstants.CL_PROTEX_PROJECT_NAME)) {
            projectName = cmd.getOptionValue(NotifierConstants.CL_PROTEX_PROJECT_NAME);
            log.info("Project name: " + projectName);
        } else {
            log.error("Must specify project name!");
            help();
            return -1;
        }

        String jiraProjectName = null;
        if (cmd.hasOption(NotifierConstants.CL_JIRA_PROJECT_NAME)) {
            jiraProjectName = cmd.getOptionValue(NotifierConstants.CL_JIRA_PROJECT_NAME);
            log.info("JIRA Project name: " + projectName);
        }

        // Config File
        if (cmd.hasOption(NotifierConstants.CL_CONFIG)) {
            String configFilePath = cmd.getOptionValue(NotifierConstants.CL_CONFIG);
            log.info("Config file location: " + configFilePath);
            configFile = new File(configFilePath);
            if (!configFile.exists()) {
                log.error("Configuration file does not exist at location: " + configFile);
                return -1;
            }
        } else {
            log.error("Must specify configuration file!");
            help();
            return -1;
        }

        // Configuration manager
        JiraIntegrationUtilityConfig jiraConfig = new JiraIntegrationUtilityConfig(configFile);

        // Call the processor
        try {
            EmailContentMap keysOnlyContentMap = createKeysOnlyContentMap();
            JiraInfo jiraInfo = jiraConfig.getJiraInfo();
            JiraConnector jiraConnector = new JiraConnector(jiraInfo.getUrl(), jiraInfo.getAdminName(),
                    jiraInfo.getAdminPassword());
            IHandler notificationHandler = new JIRAHandler(jiraConfig, jiraConnector);
            ProtexServerWrapper<ProtexProjectPojo> psw = new ProtexServerWrapper<>(jiraConfig.getServerBean(),
                    jiraConfig, true);
            NotifierProcessor enp = new NotifierProcessor(jiraConfig, psw, notificationHandler,
                    keysOnlyContentMap, projectName, jiraProjectName);
            enp.process();
        } catch (Exception e) {
            log.error("Fatal error: " + e.getMessage());
        }

        log.info("Exiting.");
        return 0;

    } catch (ParseException e) {
        log.error("Unable to parse command line arguments: " + e.getMessage());
        help();
        return -1;
    }
}

From source file:com.blackducksoftware.tools.notifiers.email.EmailNotifierUtility.java

static int process(String[] args) {
    System.out.println("Email Notifier for Black Duck Suite");
    CommandLineParser parser = new DefaultParser();

    options.addOption("h", "help", false, "show help.");

    Option protexProjectNameOption = new Option(NotifierConstants.CL_PROTEX_PROJECT_NAME, true,
            "Name of Project (required)");
    protexProjectNameOption.setRequired(true);
    options.addOption(protexProjectNameOption);

    Option configFileOption = new Option("config", true, "Location of configuration file (required)");
    configFileOption.setRequired(true);//  ww w . j a v a  2s .  co  m
    options.addOption(configFileOption);

    Option templateFileOption = new Option("template", true, "Location of email template file (optional)");
    templateFileOption.setRequired(false);
    options.addOption(templateFileOption);

    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            help();
            return 0;
        }

        String projectName = null;
        File configFile = null;
        String templateFileLocation = null;
        if (cmd.hasOption(NotifierConstants.CL_PROTEX_PROJECT_NAME)) {
            projectName = cmd.getOptionValue(NotifierConstants.CL_PROTEX_PROJECT_NAME);
            log.info("Project name: " + projectName);
        } else {
            log.error("Must specify project name!");
            help();
            return -1;
        }

        // Config File
        if (cmd.hasOption(NotifierConstants.CL_CONFIG)) {
            String configFilePath = cmd.getOptionValue(NotifierConstants.CL_CONFIG);
            log.info("Config file location: " + configFilePath);
            configFile = new File(configFilePath);
            if (!configFile.exists()) {
                log.error("Configuration file does not exist at location: " + configFile);
                return -1;
            }
        } else {
            log.error("Must specify configuration file!");
            help();
            return -1;
        }

        if (cmd.hasOption(NotifierConstants.CL_TEMPLATE_FILE)) {
            templateFileLocation = cmd.getOptionValue(NotifierConstants.CL_TEMPLATE_FILE);
            log.info("Template file location: " + templateFileLocation);
        }

        // Configuration manager
        EmailNotifierUtilityConfig emailConfig = new EmailNotifierUtilityConfig(configFile);

        // Call the processor
        try {
            CFEmailNotifier emailer = new CFEmailNotifier(emailConfig);
            if (!emailer.isConfigured()) {
                throw new NotifierException("Email Configuration not properly configured.");
            }
            // Make sure the template is parsed now
            // If user did not specify template file, use default resource
            // package.
            if (templateFileLocation == null) {
                templateFileLocation = ClassLoader
                        .getSystemResource(NotifierConstants.PROTEX_EMAIL_SUCCESS_TEMPLATE).getFile();
            }
            emailer.configureContentMap(templateFileLocation);

            IHandler notificationHandler = new EmailHandler(emailConfig, emailer);
            ProtexServerWrapper<ProtexProjectPojo> psw = new ProtexServerWrapper<>(emailConfig.getServerBean(),
                    emailConfig, true);
            NotifierProcessor enp = new NotifierProcessor(emailConfig, psw, notificationHandler,
                    emailer.getEmailContentMap(), projectName, projectName);
            enp.process();
        } catch (Exception e) {
            log.error("Fatal error: " + e.getMessage());
        }

        log.info("Exiting.");
        return 0;

    } catch (ParseException e) {
        log.error("Unable to parse command line arguments: " + e.getMessage());
        help();
        return -1;
    }
}

From source file:com.pinterest.rocksplicator.Participant.java

private static Options constructCommandLineOptions() {
    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper addresses")
            .create();/* w w  w .ja  va2  s .c o  m*/
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddresses(Required)");

    Option clusterOption = OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option domainOption = OptionBuilder.withLongOpt(domain).withDescription("Provide instance domain").create();
    domainOption.setArgs(1);
    domainOption.setRequired(true);
    domainOption.setArgName("Instance domain (Required)");

    Option hostOption = OptionBuilder.withLongOpt(hostAddress).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

    Option portOption = OptionBuilder.withLongOpt(hostPort).withDescription("Provide host port").create();
    portOption.setArgs(1);
    portOption.setRequired(true);
    portOption.setArgName("Host port (Required)");

    Option stateModelOption = OptionBuilder.withLongOpt(stateModel).withDescription("StateModel Type").create();
    stateModelOption.setArgs(1);
    stateModelOption.setRequired(true);
    stateModelOption.setArgName("StateModel Type (Required)");

    Option configPostUrlOption = OptionBuilder.withLongOpt(configPostUrl).withDescription("URL to post config")
            .create();
    configPostUrlOption.setArgs(1);
    configPostUrlOption.setRequired(true);
    configPostUrlOption.setArgName("URL to post config (Required)");

    Options options = new Options();
    options.addOption(zkServerOption).addOption(clusterOption).addOption(domainOption).addOption(hostOption)
            .addOption(portOption).addOption(stateModelOption).addOption(configPostUrlOption);
    return options;
}

From source file:com.linkedin.helix.webapp.RestAdminApplication.java

@SuppressWarnings("static-access")
private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(HELP).withDescription("Prints command-line options info")
            .create();/*from  ww w  .j av  a 2  s  .  c  o m*/
    helpOption.setArgs(0);
    helpOption.setRequired(false);
    helpOption.setArgName("print help message");

    Option zkServerOption = OptionBuilder.withLongOpt(ZKSERVERADDRESS)
            .withDescription("Provide zookeeper address").create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("ZookeeperServerAddress(Required)");

    Option portOption = OptionBuilder.withLongOpt(PORT).withDescription("Provide web service port").create();
    portOption.setArgs(1);
    portOption.setRequired(false);
    portOption.setArgName("web service port, default: " + DEFAULT_PORT);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(zkServerOption);
    options.addOption(portOption);

    return options;
}

From source file:com.linkedin.helix.mock.storage.MockHealthReportParticipant.java

@SuppressWarnings("static-access")
synchronized private static Options constructCommandLineOptions() {
    Option helpOption = OptionBuilder.withLongOpt(help).withDescription("Prints command-line options info")
            .create();/*from ww w. j a va2s.  c om*/

    Option clusterOption = OptionBuilder.withLongOpt(cluster).withDescription("Provide cluster name").create();
    clusterOption.setArgs(1);
    clusterOption.setRequired(true);
    clusterOption.setArgName("Cluster name (Required)");

    Option hostOption = OptionBuilder.withLongOpt(host).withDescription("Provide host name").create();
    hostOption.setArgs(1);
    hostOption.setRequired(true);
    hostOption.setArgName("Host name (Required)");

    Option portOption = OptionBuilder.withLongOpt(port).withDescription("Provide host port").create();
    portOption.setArgs(1);
    portOption.setRequired(true);
    portOption.setArgName("Host port (Required)");

    Option zkServerOption = OptionBuilder.withLongOpt(zkServer).withDescription("Provide zookeeper address")
            .create();
    zkServerOption.setArgs(1);
    zkServerOption.setRequired(true);
    zkServerOption.setArgName("Zookeeper server address(Required)");

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(clusterOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(zkServerOption);

    return options;
}

From source file:com.opengamma.integration.tool.marketdata.MarketDataSnapshotTool.java

private static Option createViewNameOption() {
    final Option option = new Option(VIEW_NAME_OPTION, "viewName", true, "the view definition name");
    option.setArgName("view name");
    option.setRequired(true);
    return option;
}

From source file:com.ibm.watson.app.qaclassifier.tools.GenerateTrainingAndPopulationData.java

private static Option createOption(String opt, String longOpt, boolean hasArg, String description,
        boolean required, String argName) {
    Option option = new Option(opt, longOpt, hasArg, description);
    option.setRequired(required);
    option.setArgName(argName);// w  w  w .  j a  v  a 2s.  co  m
    return option;
}