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

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

Introduction

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

Prototype

public Option(String opt, boolean hasArg, String description) throws IllegalArgumentException 

Source Link

Document

Creates an Option using the specified parameters.

Usage

From source file:edu.vt.middleware.ldap.cli.AddOperationCli.java

/** {@inheritDoc} */
@Override/*w w  w . j  a v a 2  s . c  om*/
protected void initOptions() {
    options.addOption(new Option(OPT_FILE, true, "LDIF file"));

    final Map<String, String> desc = getArgDesc(ConnectionConfig.class);
    for (String s : ConnectionConfigPropertySource.getProperties()) {
        options.addOption(new Option(s, true, desc.get(s)));
    }
    super.initOptions();
}

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   www .j a  va2 s  . 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:edu.vt.middleware.ldap.cli.CompareOperationCli.java

/** {@inheritDoc} */
@Override//  w ww .  j a  v  a2s. com
protected void initOptions() {
    options.addOption(new Option(OPT_DN, true, "entry DN"));
    options.addOption(
            new Option(OPT_ATTR, true, "colon delimited name value pair (attr:value|attr::b64value)"));

    final Map<String, String> desc = getArgDesc(ConnectionConfig.class);
    for (String s : ConnectionConfigPropertySource.getProperties()) {
        options.addOption(new Option(s, true, desc.get(s)));
    }
    super.initOptions();
}

From source file:de.topobyte.utilities.apache.commons.cli.OptionHelper.java

/**
 * Add a short option to the options specified by parameters
 * /*from  w ww  .j  av  a2s .c  o  m*/
 * @param options
 *            the options to add to.
 * @param opt
 *            the short option name.
 * @param hasArg
 *            whether it expects an argument
 * @param required
 *            whether this is a required option.
 * @param argName
 *            the name of the argument.
 * @param description
 *            the option description
 * @return the Option object created.
 */
public static Option addS(Options options, String opt, boolean hasArg, boolean required, String argName,
        String description) {
    Option option = new Option(opt, hasArg, description);
    option.setRequired(required);
    option.setArgName(argName);
    options.addOption(option);
    return option;
}

From source file:edu.vt.middleware.crypt.digest.DigestCli.java

/** {@inheritDoc} */
protected void initOptions() {
    super.initOptions();

    final Option algorithm = new Option(OPT_ALG, true, "digest algorithm name");
    algorithm.setArgName("name");
    algorithm.setOptionalArg(false);//from  w  w w .  java 2  s .c  om

    final Option salt = new Option(OPT_SALT, true, "initialize digest with salt before hashing data");
    salt.setArgName("hex_salt");
    salt.setOptionalArg(false);

    final Option infile = new Option(OPT_INFILE, true, "file to digest; defaults to STDIN");
    infile.setArgName("filepath");
    infile.setOptionalArg(false);

    final Option encoding = new Option(OPT_ENCODING, true, "output encoding format, either hex or base64");
    encoding.setArgName("encoding");
    encoding.setOptionalArg(false);

    options.addOption(algorithm);
    options.addOption(salt);
    options.addOption(infile);
    options.addOption(encoding);
}

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);/*from  w  w w  .  jav  a2s  . 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:edu.vt.middleware.ldap.LdapCli.java

/** {@inheritDoc} */
protected void initOptions() {
    super.initOptions(new LdapConfigPropertyInvoker(LdapConfig.class, LdapConfig.PROPERTIES_DOMAIN));

    options.addOption(new Option(OPT_QUERY, true, ""));
}

From source file:hu.bme.mit.trainbenchmark.config.TrainBenchmarkConfig.java

protected static Option requiredOption(final String name, final String description) {
    final Option option = new Option(name, true, description);
    option.setRequired(true);//  w ww  .  j av  a  2s  . c  om
    return option;
}

From source file:dk.hippogrif.prettyxml.app.Main.java

private static Options mkOptions() {
    Options options = new Options();
    options.addOption("h", false, "help");
    options.addOption("v", false, "version");
    options.addOption("s", false, "sort attributes on name");
    options.addOption("a", false, "indent attributes");
    Option option;/*from ww  w .  j a  v a 2 s.  c  o  m*/
    option = new Option("n", true, "no of spaces to indent, default 2");
    option.setArgName("no");
    options.addOption(option);
    option = new Option("p", true, "property file holding output format and options");
    option.setArgName("file");
    options.addOption(option);
    option = new Option("t", true, "an xslt pipeline of one or more stylesheets separated by ;");
    option.setArgName("files");
    options.addOption(option);
    option = new Option("i", true, "input file");
    option.setArgName("file");
    options.addOption(option);
    option = new Option("u", true, "input URL");
    option.setArgName("url");
    options.addOption(option);
    option = new Option("o", true, "output file");
    option.setArgName("file");
    options.addOption(option);
    return options;
}

From source file:com.netscape.cmstools.CMCSharedToken.java

public static Options createOptions() {

    Options options = new Options();

    Option option = new Option("d", true, "Security database location");
    option.setArgName("database");
    options.addOption(option);//from  w  ww  .  j a v  a  2  s.  co  m

    option = new Option("h", true, "Security token name");
    option.setArgName("token");
    options.addOption(option);

    option = new Option("o", true, "Output file to store base-64 secret data");
    option.setArgName("output");
    options.addOption(option);

    option = new Option("p", true, "password");
    option.setArgName("password");
    options.addOption(option);

    option = new Option("s", true, "passphrase");
    option.setArgName("passphrase");
    options.addOption(option);

    option = new Option("b", true, "PEM issuance protection certificate");
    option.setArgName("issuance protection cert");
    options.addOption(option);

    option = new Option("n", true, "Issuance Protection certificate nickname");
    option.setArgName("issuance protection cert nickname");
    options.addOption(option);

    options.addOption("v", "verbose", false, "Run in verbose mode.");
    options.addOption(null, "help", false, "Show help message.");

    return options;
}