Search in sources :

Example 86 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project buck by facebook.

the class StringSetOptionHandlerTest method testOptionSpecifiedMultipleTimes.

@Test
public void testOptionSpecifiedMultipleTimes() throws CmdLineException {
    TestBean bean = new TestBean();
    CmdLineParser parser = new CmdLineParser(bean);
    parser.parseArgument("--option1", "a", "b", "--option2", "c", "d", "--option1", "e", "f", "--option2", "g", "h");
    assertEquals(ImmutableSet.of("a", "b", "e", "f"), bean.getOption1());
    assertEquals(ImmutableSet.of("c", "d", "g", "h"), bean.getOption2());
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) Test(org.junit.Test)

Example 87 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project hudson-2.x by hudson.

the class CLICommand method main.

public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) {
    this.stdin = new BufferedInputStream(stdin);
    this.stdout = stdout;
    this.stderr = stderr;
    this.locale = locale;
    this.channel = Channel.current();
    registerOptionHandlers();
    CmdLineParser p = new CmdLineParser(this);
    // add options from the authenticator
    SecurityContext sc = SecurityContextHolder.getContext();
    Authentication old = sc.getAuthentication();
    CliAuthenticator authenticator = Hudson.getInstance().getSecurityRealm().createCliAuthenticator(this);
    new ClassParser().parse(authenticator, p);
    try {
        p.parseArgument(args.toArray(new String[args.size()]));
        Authentication auth = authenticator.authenticate();
        if (auth == Hudson.ANONYMOUS)
            auth = loadStoredAuthentication();
        // run the CLI with the right credential
        sc.setAuthentication(auth);
        if (!(this instanceof LoginCommand || this instanceof HelpCommand))
            Hudson.getInstance().checkPermission(Hudson.READ);
        return run();
    } catch (CmdLineException e) {
        stderr.println(e.getMessage());
        printUsage(stderr, p);
        return -1;
    } catch (AbortException e) {
        // signals an error without stack trace
        stderr.println(e.getMessage());
        return -1;
    } catch (Exception e) {
        e.printStackTrace(stderr);
        return -1;
    } finally {
        // restore
        sc.setAuthentication(old);
    }
}
Also used : CliAuthenticator(hudson.security.CliAuthenticator) CmdLineParser(org.kohsuke.args4j.CmdLineParser) BufferedInputStream(java.io.BufferedInputStream) Authentication(org.acegisecurity.Authentication) SecurityContext(org.acegisecurity.context.SecurityContext) CmdLineException(org.kohsuke.args4j.CmdLineException) AbortException(hudson.AbortException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException) ClassParser(org.kohsuke.args4j.ClassParser) AbortException(hudson.AbortException)

Example 88 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project pinot by linkedin.

the class DictionaryToRawIndexConverter method main.

/**
   * Main method for the class.
   *
   * @param args Arguments for the converter
   * @throws Exception
   */
public static void main(String[] args) throws Exception {
    DictionaryToRawIndexConverter converter = new DictionaryToRawIndexConverter();
    CmdLineParser parser = new CmdLineParser(converter);
    parser.parseArgument(args);
    converter.convert();
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser)

Example 89 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project pinot by linkedin.

the class ColumnarToStarTreeConverter method main.

/**
   * Main driver for the converter class.
   *
   * @param args Command line arguments
   * @throws Exception
   */
public static void main(String[] args) throws Exception {
    ColumnarToStarTreeConverter converter = new ColumnarToStarTreeConverter();
    CmdLineParser parser = new CmdLineParser(converter);
    parser.parseArgument(args);
    if (converter._help) {
        printUsage();
        return;
    }
    converter.convert();
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser)

Example 90 with CmdLineParser

use of org.kohsuke.args4j.CmdLineParser in project pinot by linkedin.

the class SegmentDumpTool method doMain.

public void doMain(String[] args) throws Exception {
    CmdLineParser parser = new CmdLineParser(this);
    parser.parseArgument(args);
    File segmentDir = new File(segmentPath);
    SegmentMetadata metadata = new SegmentMetadataImpl(segmentDir);
    // All columns by default
    if (columnNames == null) {
        columnNames = new ArrayList<String>(metadata.getSchema().getColumnNames());
        Collections.sort(columnNames);
    }
    IndexSegment indexSegment = Loaders.IndexSegment.load(segmentDir, ReadMode.mmap);
    Map<String, Dictionary> dictionaries = new HashMap<String, Dictionary>();
    Map<String, BlockSingleValIterator> iterators = new HashMap<String, BlockSingleValIterator>();
    for (String columnName : columnNames) {
        DataSource dataSource = indexSegment.getDataSource(columnName);
        dataSource.open();
        Block block = dataSource.nextBlock();
        BlockValSet blockValSet = block.getBlockValueSet();
        BlockSingleValIterator itr = (BlockSingleValIterator) blockValSet.iterator();
        iterators.put(columnName, itr);
        dictionaries.put(columnName, dataSource.getDictionary());
    }
    System.out.print("Doc\t");
    for (String columnName : columnNames) {
        System.out.print(columnName);
        System.out.print("\t");
    }
    System.out.println();
    for (int i = 0; i < indexSegment.getSegmentMetadata().getTotalDocs(); i++) {
        System.out.print(i);
        System.out.print("\t");
        for (String columnName : columnNames) {
            FieldSpec.DataType columnType = metadata.getSchema().getFieldSpecFor(columnName).getDataType();
            BlockSingleValIterator itr = iterators.get(columnName);
            Integer encodedValue = itr.nextIntVal();
            Object value = dictionaries.get(columnName).get(encodedValue);
            System.out.print(value);
            System.out.print("\t");
        }
        System.out.println();
    }
    if (dumpStarTree) {
        System.out.println();
        File starTreeFile = new File(segmentDir, V1Constants.STAR_TREE_INDEX_FILE);
        StarTreeInterf tree = StarTreeSerDe.fromFile(starTreeFile, ReadMode.mmap);
        tree.printTree();
    }
}
Also used : Dictionary(com.linkedin.pinot.core.segment.index.readers.Dictionary) CmdLineParser(org.kohsuke.args4j.CmdLineParser) HashMap(java.util.HashMap) IndexSegment(com.linkedin.pinot.core.indexsegment.IndexSegment) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) DataSource(com.linkedin.pinot.core.common.DataSource) SegmentMetadata(com.linkedin.pinot.common.segment.SegmentMetadata) BlockSingleValIterator(com.linkedin.pinot.core.common.BlockSingleValIterator) Block(com.linkedin.pinot.core.common.Block) BlockValSet(com.linkedin.pinot.core.common.BlockValSet) StarTreeInterf(com.linkedin.pinot.core.startree.StarTreeInterf) SegmentMetadataImpl(com.linkedin.pinot.core.segment.index.SegmentMetadataImpl) File(java.io.File)

Aggregations

CmdLineParser (org.kohsuke.args4j.CmdLineParser)119 CmdLineException (org.kohsuke.args4j.CmdLineException)80 File (java.io.File)16 Test (org.junit.Test)14 IOException (java.io.IOException)11 HyracksConnection (org.apache.hyracks.api.client.HyracksConnection)10 IHyracksClientConnection (org.apache.hyracks.api.client.IHyracksClientConnection)10 ArrayList (java.util.ArrayList)9 JobId (org.apache.hyracks.api.job.JobId)9 JobSpecification (org.apache.hyracks.api.job.JobSpecification)9 PrintStream (java.io.PrintStream)6 FileOutputStream (java.io.FileOutputStream)4 List (java.util.List)4 FeatureExtractors (io.anserini.ltr.feature.FeatureExtractors)3 Qrels (io.anserini.util.Qrels)3 Directory (org.apache.lucene.store.Directory)3 FSDirectory (org.apache.lucene.store.FSDirectory)3 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2