Search in sources :

Example 1 with ArgumentOptions

use of net.morimekta.console.args.ArgumentOptions 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)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Argument (net.morimekta.console.args.Argument)1 ArgumentException (net.morimekta.console.args.ArgumentException)1 ArgumentOptions (net.morimekta.console.args.ArgumentOptions)1 ArgumentParser (net.morimekta.console.args.ArgumentParser)1 Flag (net.morimekta.console.args.Flag)1 Option (net.morimekta.console.args.Option)1 Parser.dir (net.morimekta.console.util.Parser.dir)1 Parser.file (net.morimekta.console.util.Parser.file)1 Parser.outputDir (net.morimekta.console.util.Parser.outputDir)1 STTY (net.morimekta.console.util.STTY)1 ProvidenceConfigException (net.morimekta.providence.config.ProvidenceConfigException)1 UncheckedProvidenceConfigException (net.morimekta.providence.config.UncheckedProvidenceConfigException)1 Generator (net.morimekta.providence.generator.Generator)1