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();
}
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations