Example usage for org.apache.commons.cli2 CommandLine getValues

List of usage examples for org.apache.commons.cli2 CommandLine getValues

Introduction

In this page you can find the example usage for org.apache.commons.cli2 CommandLine getValues.

Prototype

List getValues(final Option option);

Source Link

Document

Retrieves the Argument values associated with the specified Option

Usage

From source file:org.mzd.shap.spring.cli.ExportData.java

@Override
@SuppressWarnings("unchecked")
public void execute(String[] args) {
    try {//from  w ww  .j  av a2s.  c o  m
        CommandLine cl = getApp().parseArguments(args);

        String[] xmlPath = { "datasource-context.xml", "service-context.xml", "orm-context.xml" };

        getApp().startApplication(xmlPath, true);

        // Target
        DomainTarget target = null;
        if (cl.hasOption(SAMPLE_ID)) {
            target = DomainTarget.SAMPLE;
        } else if (cl.hasOption(SEQUENCE_ID)) {
            target = DomainTarget.SEQUENCE;
        } else if (cl.hasOption(FEATURE_ID)) {
            target = DomainTarget.FEATURE;
        } else if (cl.hasOption(REF_BY_ASSOC)) {
            target = DomainTarget.DEFERRED;
        }

        // Taxonomy filter
        List<Taxonomy> excludedTaxa = new ArrayList<Taxonomy>();
        if (cl.hasOption(TAXON)) {
            for (Object obj : cl.getValues(TAXON)) {
                try {
                    excludedTaxa.add(Taxonomy.valueOf(((String) obj).toUpperCase()));
                } catch (IllegalArgumentException ex) {
                    throw new ApplicationException("Unknown taxon name [" + obj + "]", ex);
                }
            }
        }

        // Source
        List<String> idList = null;
        if (cl.hasOption(LIST)) {
            idList = cl.getValues(LIST);
        } else if (cl.hasOption(INPUT_FILE)) {
            idList = readIdFile((File) cl.getValue(INPUT_FILE));
        }

        // Destination
        File outputFile = (File) cl.getValue(OUTPUT_FILE);
        if (outputFile.exists()) {
            throw new IOException("Output file [" + outputFile.getPath() + "] already exists");
        }

        // Format
        if (cl.hasOption(ANNOTATION)) {
            writeAnnotation(target, idList, excludedTaxa, outputFile);
        } else if (cl.hasOption(FASTA)) {
            writeFasta(target, cl.hasOption(FASTA_FEATURES), cl.hasOption(FEATURE_TRANSLATE),
                    cl.hasOption(FASTA_LONG_HEADER), idList, excludedTaxa, outputFile);
        } else if (cl.hasOption(GENBANK)) {
            writeGenbank(target, idList, excludedTaxa, outputFile);
        }
        //         else if (cl.hasOption(HISTOGRAM)) {
        //            writeHistogram(
        //                  target, 
        //                  (String)cl.getValue(HISTOGRAM_ANNOTATOR), 
        //                  idList, 
        //                  (Double)cl.getValue(HISTOGRAM_CONFIDENCE), 
        //                  excludedTaxa, 
        //                  outputFile);
        //         }
    } catch (Throwable t) {
        System.err.println(t.getMessage());
        System.exit(1);
    }
}

From source file:org.mzd.shap.spring.cli.ImportData.java

@Override
public void execute(String[] args) {
    try {//from   w ww.  ja  v a 2  s .  com
        CommandLine cl = getApp().parseArguments(args);

        String[] xmlPath = { "datasource-context.xml", "service-context.xml", "orm-context.xml" };

        getApp().startApplication(xmlPath, true);

        // Add an observer to show simply progress activity.
        this.dataAdminService = (DataAdminService) getApp().getContext().getBean("dataAdminService");

        if (cl.hasOption(SET_COVERAGE)) {
            String projectName = (String) cl.getValue(PROJECT);
            String sampleName = (String) cl.getValue(SAMPLE);
            File inputFile = (File) cl.getValue(SET_COVERAGE);
            setCoverage(projectName, sampleName, inputFile);
        } else if (cl.hasOption(IMPORT_SEQUENCE)) {
            String projectName = (String) cl.getValue(PROJECT);
            String sampleName = (String) cl.getValue(SAMPLE);
            File inputFile = (File) cl.getValue(IMPORT_SEQUENCE);
            getDataAdminService().addSequencesFromFasta(projectName, sampleName, inputFile);
        } else if (cl.hasOption(ADD_PROJECT)) {
            String projectName = (String) cl.getValue(PROJECT);
            String description = CommandLineApplication.concatenateValues(cl.getValues(DESCRIPTION));
            System.out.println("Adding project [" + projectName + "] [" + description + "]");
            getDataAdminService().addProject(projectName, description);
        } else if (cl.hasOption(ADD_SAMPLE)) {
            String sampleName = (String) cl.getValue(SAMPLE);
            String projectName = (String) cl.getValue(PROJECT);
            String description = CommandLineApplication.concatenateValues(cl.getValues(DESCRIPTION));
            System.out.println(
                    "Adding sample [" + sampleName + "] [" + description + "] to [" + projectName + "]");
            getDataAdminService().addSample(projectName, sampleName, description);
        } else if (cl.hasOption(ADD_SEQUENCE)) {
            String sampleName = (String) cl.getValue(SAMPLE);
            String projectName = (String) cl.getValue(PROJECT);
            String sequenceName = (String) cl.getValue(SEQUENCE);
            String description = CommandLineApplication.concatenateValues(cl.getValues(DESCRIPTION));
            System.out.println("Adding container sequence [" + sequenceName + "] [" + description + "] to ["
                    + projectName + "," + sampleName + "]");
            getDataAdminService().addSequence(projectName, sampleName, sequenceName, description);
        } else if (cl.hasOption(IMPORT_SEQUENCE_XML)) {
            String sampleName = (String) cl.getValue(SAMPLE);
            String projectName = (String) cl.getValue(PROJECT);
            String detectorName = (String) cl.getValue(DETECTOR);
            File inputFile = (File) cl.getValue(IMPORT_SEQUENCE_XML);
            System.out.println("Importing sequences from XML to [" + projectName + "," + sampleName
                    + "] registered to detector [" + detectorName + "]");
            getDataAdminService().addSequencesFromXml(projectName, sampleName, detectorName, inputFile);
        } else if (cl.hasOption(IMPORT_FEATURE_XML)) {
            String sampleName = (String) cl.getValue(SAMPLE);
            String projectName = (String) cl.getValue(PROJECT);
            String sequenceName = (String) cl.getValue(SEQUENCE);
            String detectorName = (String) cl.getValue(DETECTOR);
            File inputFile = (File) cl.getValue(IMPORT_FEATURE_XML);
            System.out.println("Importing features from XML to [" + projectName + "," + sampleName + ","
                    + sequenceName + "] " + "registered to detector [" + detectorName + "]");
            getDataAdminService().addFeaturesFromXml(projectName, sampleName, sequenceName, detectorName,
                    inputFile);
        } else if (cl.hasOption(REMOVE_SEQUENCE)) {
            File inputFile = (File) cl.getValue(REMOVE_SEQUENCE);
            removeSequence(inputFile);
        } else if (cl.hasOption(REMOVE_FEATURE)) {
            File inputFile = (File) cl.getValue(REMOVE_FEATURE);
            removeFeature(inputFile);
        }
    } catch (Throwable t) {
        System.err.println(t.getMessage());
        System.exit(1);
    }
}