Search in sources :

Example 1 with Option

use of net.morimekta.console.args.Option 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);
}
Also used : TException(org.apache.thrift.TException) Argument(net.morimekta.console.args.Argument) ArgumentParser(net.morimekta.console.args.ArgumentParser) Flag(net.morimekta.console.args.Flag) TException(org.apache.thrift.TException) IOException(java.io.IOException) ArgumentException(net.morimekta.console.args.ArgumentException) Parser.file(net.morimekta.console.util.Parser.file) Option(net.morimekta.console.args.Option) ArgumentException(net.morimekta.console.args.ArgumentException)

Example 2 with Option

use of net.morimekta.console.args.Option 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;
}
Also used : Argument(net.morimekta.console.args.Argument) Option(net.morimekta.console.args.Option) ArgumentParser(net.morimekta.console.args.ArgumentParser) Flag(net.morimekta.console.args.Flag) ConvertStreamParser(net.morimekta.providence.tools.common.formats.ConvertStreamParser)

Example 3 with Option

use of net.morimekta.console.args.Option 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;
}
Also used : FactoryLoader(net.morimekta.providence.generator.util.FactoryLoader) HelpSpec(net.morimekta.providence.tools.generator.options.HelpSpec) Parser.dir(net.morimekta.console.util.Parser.dir) URL(java.net.URL) Generator(net.morimekta.providence.generator.Generator) GeneratorSpecParser(net.morimekta.providence.tools.generator.options.GeneratorSpecParser) ProgramParser(net.morimekta.providence.reflect.parser.ProgramParser) Argument(net.morimekta.console.args.Argument) ArrayList(java.util.ArrayList) Flag(net.morimekta.console.args.Flag) HelpOption(net.morimekta.providence.tools.generator.options.HelpOption) Utils(net.morimekta.providence.tools.common.Utils) Map(java.util.Map) GeneratorSpec(net.morimekta.providence.tools.generator.options.GeneratorSpec) ArgumentParser(net.morimekta.console.args.ArgumentParser) Parser.file(net.morimekta.console.util.Parser.file) ProvidenceConfigException(net.morimekta.providence.config.ProvidenceConfigException) ArgumentOptions(net.morimekta.console.args.ArgumentOptions) GeneratorException(net.morimekta.providence.generator.GeneratorException) CommonOptions(net.morimekta.providence.tools.common.CommonOptions) IOException(java.io.IOException) GeneratorFactory(net.morimekta.providence.generator.GeneratorFactory) File(java.io.File) ArgumentException(net.morimekta.console.args.ArgumentException) List(java.util.List) JsonGeneratorFactory(net.morimekta.providence.generator.format.json.JsonGeneratorFactory) STTY(net.morimekta.console.util.STTY) UncheckedProvidenceConfigException(net.morimekta.providence.config.UncheckedProvidenceConfigException) TreeMap(java.util.TreeMap) FileManager(net.morimekta.providence.generator.util.FileManager) ThriftProgramParser(net.morimekta.providence.reflect.parser.ThriftProgramParser) Option(net.morimekta.console.args.Option) Parser.outputDir(net.morimekta.console.util.Parser.outputDir) TypeLoader(net.morimekta.providence.reflect.TypeLoader) ProvidenceTools(net.morimekta.providence.tools.common.ProvidenceTools) Argument(net.morimekta.console.args.Argument) GeneratorSpecParser(net.morimekta.providence.tools.generator.options.GeneratorSpecParser) HelpOption(net.morimekta.providence.tools.generator.options.HelpOption) HelpOption(net.morimekta.providence.tools.generator.options.HelpOption) Option(net.morimekta.console.args.Option) ArgumentOptions(net.morimekta.console.args.ArgumentOptions) ArgumentParser(net.morimekta.console.args.ArgumentParser) Flag(net.morimekta.console.args.Flag)

Example 4 with Option

use of net.morimekta.console.args.Option 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;
}
Also used : ArgumentParser(net.morimekta.console.args.ArgumentParser) Parser.dir(net.morimekta.console.util.Parser.dir) SubCommandSet(net.morimekta.console.args.SubCommandSet) CommonOptions(net.morimekta.providence.tools.common.CommonOptions) IOException(java.io.IOException) Command(net.morimekta.providence.tools.config.cmd.Command) Help(net.morimekta.providence.tools.config.cmd.Help) File(java.io.File) ArrayList(java.util.ArrayList) Validate(net.morimekta.providence.tools.config.cmd.Validate) Flag(net.morimekta.console.args.Flag) List(java.util.List) STTY(net.morimekta.console.util.STTY) Resolve(net.morimekta.providence.tools.config.cmd.Resolve) Option(net.morimekta.console.args.Option) SubCommand(net.morimekta.console.args.SubCommand) Help(net.morimekta.providence.tools.config.cmd.Help) Option(net.morimekta.console.args.Option) ArgumentParser(net.morimekta.console.args.ArgumentParser) Flag(net.morimekta.console.args.Flag)

Example 5 with Option

use of net.morimekta.console.args.Option 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;
}
Also used : Option(net.morimekta.console.args.Option) ArgumentParser(net.morimekta.console.args.ArgumentParser) Flag(net.morimekta.console.args.Flag)

Aggregations

ArgumentParser (net.morimekta.console.args.ArgumentParser)7 Option (net.morimekta.console.args.Option)7 Flag (net.morimekta.console.args.Flag)6 Argument (net.morimekta.console.args.Argument)5 IOException (java.io.IOException)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ArgumentException (net.morimekta.console.args.ArgumentException)3 Parser.dir (net.morimekta.console.util.Parser.dir)3 STTY (net.morimekta.console.util.STTY)3 Map (java.util.Map)2 Parser.file (net.morimekta.console.util.Parser.file)2 TypeLoader (net.morimekta.providence.reflect.TypeLoader)2 ThriftProgramParser (net.morimekta.providence.reflect.parser.ThriftProgramParser)2 CommonOptions (net.morimekta.providence.tools.common.CommonOptions)2 GenericUrl (com.google.api.client.http.GenericUrl)1 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)1 HttpTransport (com.google.api.client.http.HttpTransport)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1