use of net.morimekta.console.args.Flag 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.Flag 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.Flag 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.Flag in project providence by morimekta.
the class ConfigOptions method getArgumentParser.
@Override
public ArgumentParser getArgumentParser(String prog, String description) throws IOException {
ArgumentParser parser = super.getArgumentParser(prog, description);
parser.add(new Flag("--strict", "S", "Parse config strictly", this::setStrict, false));
parser.add(new Option("--include", "I", "dir", "Read config definitions from these directories.", dir(includes::add), null, true, false, false));
commandSet = new SubCommandSet<>("cmd", "Config action.", this::setCommand, null, true, getArgumentOptions());
commandSet.add(new SubCommand<>("help", "Show help for sub-commands.", false, () -> new Help(commandSet, parser), cmd -> cmd.parser(parser)));
commandSet.add(new SubCommand<>("resolve", "Resolve the resulting config.", false, Resolve::new, cmd -> cmd.parser(parser), "p", "pr"));
commandSet.add(new SubCommand<>("validate", "Validate the files, print error if not valid.", false, Validate::new, cmd -> cmd.parser(parser)));
parser.add(commandSet);
return parser;
}
use of net.morimekta.console.args.Flag in project providence by morimekta.
the class CommonOptions method getArgumentParser.
public ArgumentParser getArgumentParser(String prog, String description) throws IOException {
ArgumentParser parser = new ArgumentParser(prog, Utils.getVersionString(), description, getArgumentOptions());
parser.add(new Flag("--help", "h?", "This help listing.", 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"));
return parser;
}
Aggregations