Search in sources :

Example 86 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project newts by OpenNMS.

the class MergeSort method execute.

public void execute(String... args) throws IOException {
    CmdLineParser parser = createCmdLineParser();
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        // handling of wrong arguments
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
        return;
    }
    final MetricRegistry metrics = new MetricRegistry();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).outputTo(System.err).convertRatesTo(SECONDS).convertDurationsTo(MILLISECONDS).build();
    reporter.start(10, SECONDS);
    Meter linesMeter = metrics.meter("lines");
    Meter filesMeter = metrics.meter("files");
    Meter dirsMeter = metrics.meter("dirs");
    Meter batchMeter = metrics.meter("batches");
    Path root = m_source.toPath();
    if (m_targetDir == null) {
        m_targetDir = Files.createTempDir();
        System.err.println("Working Directory: " + m_targetDir);
    }
    LOG.debug("Scanning {} for GSOD data files...", root);
    FluentIterable<KeyedIterable<Path, Path>> dirs = FileIterable.groupFilesByDir(root);
    for (KeyedIterable<Path, Path> filesInDir : dirs) {
        Path subdir = root.relativize(filesInDir.getKey());
        String dirName = subdir.getFileName().toString();
        System.err.println("Sorted dir: " + subdir);
        FluentIterable<Iterable<String>> contentIterables = filesInDir.transform(this.<Path>meter(filesMeter)).transform(lines("YEARMODA"));
        FluentIterable<List<Iterable<String>>> batches = FluentIterable.from(Iterables.partition(contentIterables, m_mergeCount));
        FluentIterable<Iterable<GSODLine>> sortedBatches = batches.transform(lift2GsodLines()).transform(mergeSorter());
        Path sortedDir = m_targetDir.toPath().resolve(subdir);
        sortedDir.toFile().mkdirs();
        int count = 1;
        for (Iterable<GSODLine> batch : sortedBatches) {
            Path sortedFile = sortedDir.resolve(dirName + "-batch-" + (count++) + ".gz");
            System.err.println("Creating " + sortedFile);
            try (PrintStream out = open(sortedFile)) {
                out.println(HDR);
                for (GSODLine line : batch) {
                    out.println(line);
                    linesMeter.mark();
                }
            }
            batchMeter.mark();
        }
        dirsMeter.mark();
    }
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) CmdLineParser(org.kohsuke.args4j.CmdLineParser) ConsoleReporter(com.codahale.metrics.ConsoleReporter) FluentIterable(com.google.common.collect.FluentIterable) KeyedIterable(org.opennms.newts.gsod.FileIterable.KeyedIterable) Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) KeyedIterable(org.opennms.newts.gsod.FileIterable.KeyedIterable) List(java.util.List) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 87 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project jangaroo-tools by CoreMedia.

the class JoocCommandLineParser method parse.

public JoocConfiguration parse(String[] args) throws CommandLineParseException {
    JoocConfiguration config = new JoocConfiguration();
    CmdLineParser parser = new CmdLineParser(config);
    try {
        // parse the arguments.
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        StringBuilder msg = extendedUsage(parser, e);
        throw new CommandLineParseException(msg.toString(), -1);
    }
    return parseConfig(parser, config);
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) JoocConfiguration(net.jangaroo.jooc.config.JoocConfiguration) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 88 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project jangaroo-tools by CoreMedia.

the class ExmlcCommandLineParser method parse.

public ExmlConfiguration parse(String[] args) throws CommandLineParseException {
    ExmlConfiguration config = new ExmlConfiguration();
    CmdLineParser parser = new CmdLineParser(config);
    try {
        // parse the arguments.
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        StringBuilder msg = extendedUsage(parser, e);
        throw new CommandLineParseException(msg.toString(), -1);
    }
    return parseConfig(parser, config);
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) CommandLineParseException(net.jangaroo.jooc.cli.CommandLineParseException) ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 89 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project jangaroo-tools by CoreMedia.

the class PropertiesCompiler method run.

public static int run(String[] args) {
    FileLocations config = new FileLocations();
    CmdLineParser parser = new CmdLineParser(config);
    try {
        // parse the arguments.
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        StringBuilder msg = new StringBuilder();
        // if there's a problem in the command line,
        // you'll get this exception. this will report
        // an error message.
        msg.append(e.getMessage());
        msg.append("\n");
        msg.append("java -jar properties-compiler.jar [options...] source files...\n");
        // print the list of available options
        StringWriter writer = new StringWriter();
        parser.printUsage(writer, null);
        msg.append(writer.getBuffer());
        msg.append("\n");
        // print option sample. This is useful some time
        msg.append("  Example: java -jar properties-compiler.jar").append(parser.printExample(REQUIRED));
        msg.append("\n");
        // NOSONAR this is a commandline tool
        System.err.println(msg);
        return -1;
    }
    if (!config.getOutputDirectory().exists()) {
        throw new IllegalArgumentException("destination directory does not exist: " + config.getOutputDirectory().getAbsolutePath());
    }
    PropertyClassGenerator generator = new PropertyClassGenerator(config);
    generator.generate();
    return 0;
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) StringWriter(java.io.StringWriter) PropertyClassGenerator(net.jangaroo.properties.PropertyClassGenerator) FileLocations(net.jangaroo.utils.FileLocations) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 90 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project opennms by OpenNMS.

the class ResourceCli method parseArguments.

public void parseArguments(final String[] args) {
    // Parse the arguments
    final CmdLineParser cmdLineParser = new CmdLineParser(this);
    try {
        cmdLineParser.parseArgument(args);
    } catch (final CmdLineException e) {
        System.err.println("Error: " + e.getMessage() + "\n");
        displayHelp(cmdLineParser);
        System.exit(-1);
    }
    // Display help message if "--help" was used
    if (help) {
        displayHelp(cmdLineParser);
        System.exit(0);
    }
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

CmdLineException (org.kohsuke.args4j.CmdLineException)105 CmdLineParser (org.kohsuke.args4j.CmdLineParser)80 IOException (java.io.IOException)16 File (java.io.File)14 ArrayList (java.util.ArrayList)11 PrintStream (java.io.PrintStream)7 StringWriter (java.io.StringWriter)6 List (java.util.List)5 FileOutputStream (java.io.FileOutputStream)4 Path (java.nio.file.Path)4 CmdLineParser (com.google.gerrit.util.cli.CmdLineParser)3 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 Project (com.google.gerrit.reviewdb.client.Project)2 OrmException (com.google.gwtorm.server.OrmException)2 Hudson (hudson.model.Hudson)2