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

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

Introduction

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

Prototype

public static Option create(String opt) throws IllegalArgumentException 

Source Link

Document

Create an Option using the current settings and with the specified Option char.

Usage

From source file:edu.kit.dama.transfer.client.impl.BaseUserClient.java

/**
 * Adds a new option to the default command line options.
 *
 * @param pOptionName The option and the short option character.
 * @param pDescription The plain text description of the option.
 * @param pArgCount The argument count./*from   www  .  ja v a2 s.co  m*/
 * @param pLongOption The long option string.
 * @param pMandatory TRUE = This option MUST be provided.
 */
public final void addOption(String pOptionName, String pDescription, int pArgCount, String pLongOption,
        boolean pMandatory) {
    if (pOptionName == null || pDescription == null) {
        throw new IllegalArgumentException("Neither pOptionName nor pDescription must be 'null'");
    }
    OptionBuilder b = OptionBuilder.withLongOpt(pLongOption).withDescription(pDescription)
            .isRequired(pMandatory);
    if (pArgCount != 0) {
        if (pArgCount == 1) {
            b = b.hasArg();
        } else {
            b = b.hasArgs(pArgCount);
        }
    }
    OPTIONS.addOption(b.create(pOptionName));
}

From source file:com.comcast.oscar.cli.commands.OID.java

/**
 * Set option parameters for command OID
 * @return Option/*from w  ww .  j  av  a  2 s .c  om*/
 */
public static Option OptionParameters() {
    OptionBuilder.withArgName("[<OID>][<value>][<data type>]");
    OptionBuilder.hasArgs();
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("OID");
    OptionBuilder.withDescription("Insert this OID into a file when compiling. "
            + "Multiple OIDs can be inserted simultaneously (space delimited). " + "Applicable datatypes: "
            + BERService.getDataTypeStringList());
    return OptionBuilder.create("O");
}

From source file:com.comcast.oscar.cli.commands.DigitmapInsert.java

/**
 * Set option parameters for command Digitmap Insert
 * @return Option/* w  w w  . j  a  va 2  s .c o m*/
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("[<filename>][<OID>]");
    OptionBuilder.hasArgs();
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("digitmap");
    OptionBuilder.withDescription("Insert this DigitMap into a file when compiling - PacketCable ONLY. "
            + "Multiple DigitMaps can be inserted simultaneously (space delimited). " + "OID optional.");
    return OptionBuilder.create("dm");
}

From source file:com.comcast.oscar.cli.commands.TFTPServer.java

/**
 * Set option parameters for command TFTP Server Address
 * @return Option/*from   ww w.  ja  v  a2s.c  o  m*/
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("v4/v6=<tftp address>");
    OptionBuilder.hasArgs();
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("tftp");
    OptionBuilder.withDescription("Add this TFTP server during file compilation. "
            + "For IPv4 use this format for the argument: v4=<server address>. "
            + "For IPv6 use this format for the argument: v6=<server address>. "
            + "Both address versions can be inserted simultaneously (space delimited).");
    return OptionBuilder.create("T");
}

From source file:com.comcast.oscar.cli.commands.Specification.java

/**
 * Set option parameters for command Specification
 * @return Option/*  w w  w.j a va  2 s  .c o  m*/
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("d{ocsis}|p{acketcable}|d{po}e> <version");
    OptionBuilder.hasArgs();
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("spec");
    OptionBuilder.withDescription(
            "Set specification and version of the file to be compiled/decompiled EX: -s d 1.1 (DOCSIS 1.1) / -s p 1.5 (PacketCable 1.5).");
    return OptionBuilder.create("s");
}

From source file:com.comcast.oscar.cli.commands.CVC.java

/**
 * Set option parameters for command CVC
 * @return Option//from  w w w  . j  a v a2s.c om
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("c/m=<filename>");
    OptionBuilder.hasArgs();
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("certificate");
    OptionBuilder.withDescription("Add this CVC during file compilation. "
            + "For CoSigner use this format for the argument: c=<filename>. "
            + "For Manufacturer use this format for the argument: m=<filename>. "
            + "Both CVCs can be inserted simultaneously (space delimited).");
    return OptionBuilder.create("cvc");
}

From source file:com.delcyon.capo.Configuration.java

@SuppressWarnings({ "unchecked", "static-access" })
public Configuration(String... programArgs) throws Exception {

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilder = documentBuilderFactory.newDocumentBuilder();

    options = new Options();
    // the enum this is a little complicated, but it gives us a nice
    // centralized place to put all of the system parameters
    // and lets us iterate of the list of options and preferences
    PREFERENCE[] preferences = PREFERENCE.values();
    for (PREFERENCE preference : preferences) {
        // not the most elegant, but there is no default constructor, but
        // the has arguments value is always there
        OptionBuilder optionBuilder = OptionBuilder.hasArg(preference.hasArgument);
        if (preference.hasArgument == true) {
            String[] argNames = preference.arguments;
            for (String argName : argNames) {
                optionBuilder = optionBuilder.withArgName(argName);
            }/*  w  w  w . j  av  a  2 s  . com*/
        }

        optionBuilder = optionBuilder.withDescription(preference.getDescription());
        optionBuilder = optionBuilder.withLongOpt(preference.getLongOption());
        options.addOption(optionBuilder.create(preference.getOption()));

        preferenceHashMap.put(preference.toString(), preference);
    }

    //add dynamic options

    Set<String> preferenceProvidersSet = CapoApplication.getAnnotationMap()
            .get(PreferenceProvider.class.getCanonicalName());
    if (preferenceProvidersSet != null) {
        for (String className : preferenceProvidersSet) {
            Class preferenceClass = Class.forName(className).getAnnotation(PreferenceProvider.class)
                    .preferences();
            if (preferenceClass.isEnum()) {
                Object[] enumObjects = preferenceClass.getEnumConstants();
                for (Object enumObject : enumObjects) {

                    Preference preference = (Preference) enumObject;
                    //filter out any preferences that don't belong on this server or client.
                    if (preference.getLocation() != Location.BOTH) {
                        if (CapoApplication.isServer() == true && preference.getLocation() == Location.CLIENT) {
                            continue;
                        } else if (CapoApplication.isServer() == false
                                && preference.getLocation() == Location.SERVER) {
                            continue;
                        }
                    }
                    preferenceHashMap.put(preference.toString(), preference);
                    boolean hasArgument = false;
                    if (preference.getArguments() == null || preference.getArguments().length == 0) {
                        hasArgument = false;
                    } else {
                        hasArgument = true;
                    }

                    OptionBuilder optionBuilder = OptionBuilder.hasArg(hasArgument);
                    if (hasArgument == true) {
                        String[] argNames = preference.getArguments();
                        for (String argName : argNames) {
                            optionBuilder = optionBuilder.withArgName(argName);
                        }
                    }

                    optionBuilder = optionBuilder.withDescription(preference.getDescription());
                    optionBuilder = optionBuilder.withLongOpt(preference.getLongOption());
                    options.addOption(optionBuilder.create(preference.getOption()));
                }

            }
        }
    }

    // create parser
    CommandLineParser commandLineParser = new GnuParser();
    this.commandLine = commandLineParser.parse(options, programArgs);

    Preferences systemPreferences = Preferences
            .systemNodeForPackage(CapoApplication.getApplication().getClass());
    String capoDirString = null;
    while (true) {
        capoDirString = systemPreferences.get(PREFERENCE.CAPO_DIR.longOption, null);
        if (capoDirString == null) {

            systemPreferences.put(PREFERENCE.CAPO_DIR.longOption, PREFERENCE.CAPO_DIR.defaultValue);
            capoDirString = PREFERENCE.CAPO_DIR.defaultValue;
            try {
                systemPreferences.sync();
            } catch (BackingStoreException e) {
                //e.printStackTrace();            
                if (systemPreferences.isUserNode() == false) {
                    System.err.println("Problem with System preferences, trying user's");
                    systemPreferences = Preferences
                            .userNodeForPackage(CapoApplication.getApplication().getClass());
                    continue;
                } else //just bail out
                {
                    throw e;
                }

            }
        }
        break;
    }

    disableAutoSync = hasOption(PREFERENCE.DISABLE_CONFIG_AUTOSYNC);

    File capoDirFile = new File(capoDirString);
    if (capoDirFile.exists() == false) {
        if (disableAutoSync == false) {
            capoDirFile.mkdirs();
        }
    }
    File configDir = new File(capoDirFile, PREFERENCE.CONFIG_DIR.defaultValue);
    if (configDir.exists() == false) {
        if (disableAutoSync == false) {
            configDir.mkdirs();
        }
    }

    if (disableAutoSync == false) {
        capoConfigFile = new File(configDir, CONFIG_FILENAME);
        if (capoConfigFile.exists() == false) {

            Document configDocument = CapoApplication.getDefaultDocument("config.xml");

            FileOutputStream configFileOutputStream = new FileOutputStream(capoConfigFile);
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.transform(new DOMSource(configDocument), new StreamResult(configFileOutputStream));
            configFileOutputStream.close();
        }

        configDocument = documentBuilder.parse(capoConfigFile);
    } else //going memory only, because of disabled auto sync
    {
        configDocument = CapoApplication.getDefaultDocument("config.xml");
    }
    if (configDocument instanceof CDocument) {
        ((CDocument) configDocument).setSilenceEvents(true);
    }
    loadPreferences();
    preferenceValueHashMap.put(PREFERENCE.CAPO_DIR.longOption, capoDirString);
    //print out preferences
    //this also has the effect of persisting all of the default values if a values doesn't already exist
    for (PREFERENCE preference : preferences) {
        if (getValue(preference) != null) {
            CapoApplication.logger.log(Level.CONFIG, preference.longOption + "='" + getValue(preference) + "'");
        }
    }

    CapoApplication.logger.setLevel(Level.parse(getValue(PREFERENCE.LOGGING_LEVEL)));
}

From source file:fr.smartcontext.yatte.context.cli.DefaultOptionsProvider.java

/** 
 * {@inheritDoc}/*from ww w.java2s .  c  om*/
 * @see fr.smartcontext.yatte.context.cli.CLIOptionsProvider#getOptions()
 */
@Override
public Options getOptions() {
    Options options = new Options();
    OptionBuilder.withLongOpt(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_LONG_NAME);
    OptionBuilder.withDescription(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_DESCRIPTION);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_ARGUMENT_NAME);
    options.addOption(OptionBuilder.create(ApplicationParametersConstants.PROPERTIES_PATH_OPTION_NAME));

    OptionBuilder.withLongOpt(ApplicationParametersConstants.OUTPUT_OPTION_LONG_NAME);
    OptionBuilder.withDescription(ApplicationParametersConstants.OUTPUT_OPTION_DESCRIPTION);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(ApplicationParametersConstants.OUTPUT_OPTION_ARGUMENT_NAME);
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create(ApplicationParametersConstants.OUTPUT_OPTION_NAME));

    OptionBuilder.withLongOpt(ApplicationParametersConstants.TEMPLATE_OPTION_LONG_NAME);
    OptionBuilder.withDescription(ApplicationParametersConstants.TEMPLATE_OPTION_DESCRIPTION);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(ApplicationParametersConstants.TEMPLATE_OPTION_ARGUMENT_NAME);
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create(ApplicationParametersConstants.TEMPLATE_OPTION_NAME));

    return options;
}

From source file:com.comcast.oscar.cli.commands.HexDisplay.java

/**
 * Set option parameters for command Hexidecimal display
 * @return Option//from w w  w  .j  a v  a  2s .c  o m
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("t{oplevel}");
    OptionBuilder.hasArgs(1);
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("hex");
    OptionBuilder.withDescription(
            "Display the hex of the input file. Option t creates a newline at the start of every top level TLV (binary files only).");
    return OptionBuilder.create("x");
}

From source file:com.comcast.oscar.cli.commands.MergeBulk.java

/**
 * Set option parameters for command Maximum CPE
 * @return Option/*from   w  ww.  j  a  v a  2s . c  om*/
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("input dirs> <o=<output dir>> <e=<extension>> <b{inary}/t{ext}");
    OptionBuilder.hasArgs();
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("mergebulkbuild");
    OptionBuilder.withDescription("Merge multiple text files from directories into one binary. "
            + "EX: -mbb inputDirectoryModel inputDirectoryTier inputDirectoryCPE o=outputDirectory e=bin text. "
            + "Output directory, extension and b{inary}/t{ext} are optional.");
    return OptionBuilder.create("mbb");
}