use of net.morimekta.console.args.ArgumentParser in project providence by morimekta.
the class TestRunner method main.
public static void main(String... args) throws InterruptedException, TException, IOException {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "off");
ArgumentParser parser = new ArgumentParser("it-serialization", "SNAPSHOT", "Serialization speed Integration test");
TestOptions options = new TestOptions();
try {
parser.add(new Flag("--help", "h?", "Show this help message", options.help::set));
parser.add(new Flag("--no_progress", "s", "No progress output", options.no_progress::set));
parser.add(new Option("--runs", "R", "RUNS", "Number of runs to do", i32(options.runs::set), "100"));
parser.add(new Option("--generate", "g", "NUM", "Number of messages to generate", i32(options.generate::set), "10"));
parser.add(new Option("--fill_rate", "r", "FRACT", "Fill rate, 0.0 - 1.0 of fields in generated classes", dbl(options.generator::setFillRate), "1.0"));
parser.add(new Option("--load", null, "FILE", "File to load data from. Required test to match content", file(options.file::set)));
parser.add(new Option("--format", "f", "FMT", "Which format to test", oneOf(Format.class, options.format::set), "all"));
parser.add(new Argument("test", "Which test to run", oneOf(TestOptions.Test.class, options.test::set), "all"));
parser.parse(args);
if (options.help.get()) {
System.out.println("Usage: " + parser.getSingleLineUsage());
System.out.println();
parser.printUsage(System.out);
System.exit(0);
}
parser.validate();
if (options.test.get() == null || options.test.get() == TestOptions.Test.containers) {
new TestRunner<>(net.morimekta.test.providence.serialization.containers.ManyContainers.kDescriptor, net.morimekta.test.thrift.serialization.containers.ManyContainers::new, options).run();
}
if (options.test.get() == null || options.test.get() == TestOptions.Test.fields) {
new TestRunner<>(net.morimekta.test.providence.serialization.messages.ManyFields.kDescriptor, net.morimekta.test.thrift.serialization.messages.ManyFields::new, options).run();
}
if (options.test.get() == null || options.test.get() == TestOptions.Test.r_fields) {
new TestRunner<>(net.morimekta.test.providence.serialization.messages.ManyRequiredFields.kDescriptor, net.morimekta.test.thrift.serialization.messages.ManyRequiredFields::new, options).run();
}
if (options.test.get() == null || options.test.get() == TestOptions.Test.deep) {
new TestRunner<>(net.morimekta.test.providence.serialization.deep.DeepStructure.kDescriptor, net.morimekta.test.thrift.serialization.deep.DeepStructure::new, options).run();
}
System.out.println();
System.exit(0);
} catch (ArgumentException e) {
System.err.println("Argument: " + e.getMessage());
System.err.println();
System.err.println("Usage: " + parser.getSingleLineUsage());
System.err.println();
parser.printUsage(System.err);
} catch (TException e) {
e.printStackTrace();
System.err.println("TException" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
System.exit(1);
}
use of net.morimekta.console.args.ArgumentParser in project providence by morimekta.
the class ConvertOptions method getArgumentParser.
@Override
public ArgumentParser getArgumentParser(String prog, String description) throws IOException {
ArgumentParser parser = super.getArgumentParser(prog, description);
parser.add(new Option("--include", "I", "dir", "Include from directories.", dir(this::addInclude), "${PWD}", true, false, false));
parser.add(new Option("--in", "i", "spec", "Input specification", new ConvertStreamParser(in).andApply(this::setIn), in.toString()));
parser.add(new Option("--out", "o", "spec", "Output specification", new ConvertStreamParser(out).andApply(this::setOut), out.toString()));
parser.add(new Flag("--strict", "S", "Read incoming messages strictly.", this::setStrict));
parser.add(new Flag("--list-types", "L", "List the parsed types based on the input files", this::setListTypes));
parser.add(new Argument("type", "Qualified identifier name from definitions to use for parsing source file.", this::setType));
return parser;
}
use of net.morimekta.console.args.ArgumentParser in project providence by morimekta.
the class GeneratorOptions method getArgumentParser.
public ArgumentParser getArgumentParser(String prog, String description) throws IOException {
ArgumentOptions opts = ArgumentOptions.defaults(tty).withMaxUsageWidth(120);
ArgumentParser parser = new ArgumentParser(prog, Utils.getVersionString(), description, opts);
parser.add(new Option("--gen", "g", "generator", "Generate files for this language spec.", new GeneratorSpecParser(this::getFactories).andApply(this::setGenerator)));
parser.add(new HelpOption("--help", "h?", "Show this help or about language.", this::getFactories, this::setHelp));
parser.add(new Flag("--verbose", "V", "Show verbose output and error messages.", this::setVerbose));
parser.add(new Flag("--version", "v", "Show program version.", this::setVersion));
parser.add(new Option("--rc", null, "FILE", "Providence RC to use", file(this::setRc), "~" + File.separator + ".pvdrc"));
parser.add(new Option("--include", "I", "dir", "Allow includes of files in directory", dir(this::addInclude), null, true, false, false));
parser.add(new Option("--out", "o", "dir", "Output directory", outputDir(this::setOut), "${PWD}"));
parser.add(new Flag("--require-field-id", null, "Require all fields to have a defined ID", this::setRequireFieldId));
parser.add(new Flag("--require-enum-value", null, "Require all enum values to have a defined ID", this::setRequireEnumValue));
parser.add(new Flag("--allow-language-reserved-names", null, "Allow language-reserved words in type names", this::setAllowLanguageReservedNames, true));
parser.add(new Flag("--no-language-reserved-names", null, "Do not allow language-reserved words in type names", b -> this.setAllowLanguageReservedNames(!b)));
parser.add(new Flag("--skip-if-missing-namespace", "N", "Skip generation for files without requested namespace", this::setSkipIfMissingNamespace));
parser.add(new Option("--add-generator", null, "FILE", "Add extra generator .jar file", file(extraGenerators::add)));
parser.add(new Argument("file", "Files to compile.", file(this::addFile), null, null, true, true, false));
return parser;
}
use of net.morimekta.console.args.ArgumentParser in project providence by morimekta.
the class RPC method run.
@SuppressWarnings("unchecked")
void run(String... args) {
try {
ArgumentParser cli = options.getArgumentParser("pvdrpc", "Providence RPC Tool");
try {
cli.parse(args);
if (options.showHelp()) {
System.out.println("Providence RPC Tool - " + getVersionString());
System.out.println("Usage: " + cli.getSingleLineUsage());
System.out.println();
System.out.println("Example code to run:");
System.out.println("$ cat call.json | pvdrpc -I thrift/ -s cal.Calculator http://localhost:8080/service");
System.out.println("$ pvdrpc -i binary,file:my.data -f json_protocol -I thrift/ -s cal.Calculator http://localhost:8080/service");
System.out.println();
cli.printUsage(System.out);
System.out.println();
System.out.println("Available formats are:");
for (Format format : Format.values()) {
System.out.println(String.format(" - %-20s : %s", format.name(), format.desc));
}
return;
} else if (options.showVersion()) {
System.out.println("Providence RPC Tool - " + getVersionString());
return;
}
cli.validate();
MessageReader in = options.getInput();
MessageWriter out = options.getOutput();
PService service = options.getDefinition();
PServiceCallHandler handler = options.getHandler();
PServiceCall call = in.read(service);
in.close();
PServiceCall resp = handler.handleCall(call, service);
out.write(resp);
out.separator();
out.close();
if (options.out.base64mime && options.out.file == null) {
System.out.println();
}
return;
} catch (ConnectException e) {
System.out.flush();
System.err.format("Unable to connect to %s: %s%n", options.endpoint, e.getMessage());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (HttpResponseException e) {
System.out.flush();
System.err.println("Received " + e.getStatusCode() + " " + e.getStatusMessage());
System.err.println(" - from: " + options.endpoint);
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (ArgumentException e) {
System.out.flush();
System.err.println(e.getMessage());
System.err.println("Usage: " + cli.getSingleLineUsage());
System.err.println();
System.err.println("Run $ pvdrpc --help # for available options.");
} catch (SerializerException e) {
System.out.flush();
System.err.println("Serializer error: " + e.asString());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (UncheckedIOException | IOException e) {
System.out.flush();
System.err.println("I/O error: " + e.getMessage());
if (options.verbose()) {
System.out.flush();
e.printStackTrace();
}
} catch (IllegalArgumentException e) {
System.out.flush();
System.err.println("Internal Error: " + e.getMessage());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
}
} catch (RuntimeException | IOException e) {
System.out.flush();
System.err.println("Unchecked exception: " + e.getMessage());
if (options.verbose()) {
System.out.flush();
e.printStackTrace();
}
}
System.err.flush();
exit(1);
}
use of net.morimekta.console.args.ArgumentParser in project providence by morimekta.
the class Config method run.
public void run(String... args) {
ConfigOptions op = new ConfigOptions(tty);
try {
ArgumentParser cli = op.getArgumentParser("pvdcfg", "Providence Config Tool");
try {
cli.parse(args);
if (op.showHelp()) {
System.out.println(cli.getDescription() + " - " + getVersionString());
System.out.println("Usage: " + cli.getSingleLineUsage());
System.out.println();
cli.printUsage(System.out);
System.out.println();
System.out.println("Available Commands:");
System.out.println();
op.getCommandSet().printUsage(System.out);
return;
} else if (op.showVersion()) {
System.out.println(cli.getDescription() + " - " + getVersionString());
return;
}
cli.validate();
op.execute();
return;
} catch (ArgumentException e) {
System.err.println("Invalid argument: " + e.getMessage());
System.err.println("Usage: " + cli.getSingleLineUsage());
if (op.verbose()) {
e.printStackTrace();
}
} catch (ParseException e) {
System.out.flush();
System.err.println(e.asString());
if (op.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (TokenizerException e) {
System.out.flush();
System.err.println(e.asString());
if (op.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (SerializerException e) {
System.out.flush();
System.err.println("Serialization error: " + e.toString());
if (op.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (IOException | RuntimeException e) {
System.out.flush();
System.err.println("IO Error: " + e.toString());
if (op.verbose()) {
System.err.println();
e.printStackTrace();
}
}
} catch (Exception e) {
System.out.flush();
System.err.println("Unhandled exception: " + e.toString());
if (op.verbose()) {
System.err.println();
e.printStackTrace();
}
}
exit(1);
}
Aggregations