Search in sources :

Example 1 with ConvertStreamParser

use of net.morimekta.providence.tools.common.formats.ConvertStreamParser 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 2 with ConvertStreamParser

use of net.morimekta.providence.tools.common.formats.ConvertStreamParser in project providence by morimekta.

the class RPCOptions 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", "Allow includes of files in directory", dir(this::addInclude), null, 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 Option("--service", "s", "srv", "Qualified identifier name from definitions to use for parsing source file.", this::setService, null, false, true, false));
    parser.add(new Option("--format", "f", "fmt", "Request RPC format", oneOf(Format.class, this::setFormat), format.name()));
    parser.add(new Option("--connect_timeout", "C", "ms", "Connection timeout in milliseconds. 0 means infinite.", i32(this::setConnectTimeout), "10000"));
    parser.add(new Option("--read_timeout", "R", "ms", "Request timeout in milliseconds. 0 means infinite.", i32(this::setReadTimeout), "10000"));
    parser.add(new Option("--header", "H", "hdr", "Header to set on the request, K/V separated by ':'.", this::addHeaders, null, true, false, false));
    parser.add(new Flag("--strict", "S", "Read incoming messages strictly.", this::setStrict));
    parser.add(new Argument("URI", "The endpoint URI", this::setEndpoint, null, s -> {
        try {
            if (!s.contains("://"))
                return false;
            URI uri = new URI(s);
            if (isNullOrEmpty(uri.getAuthority())) {
                throw new ArgumentException("Missing authority in URI: '" + s + "'");
            }
            return true;
        } catch (URISyntaxException e) {
            throw new ArgumentException(e, e.getMessage());
        }
    }, false, true, false));
    return parser;
}
Also used : ThriftSerializerProvider(net.morimekta.providence.thrift.ThriftSerializerProvider) Parser.dir(net.morimekta.console.util.Parser.dir) URISyntaxException(java.net.URISyntaxException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Parser.i32(net.morimekta.console.util.Parser.i32) HashMap(java.util.HashMap) HttpClientHandler(net.morimekta.providence.client.HttpClientHandler) MessageWriter(net.morimekta.providence.mio.MessageWriter) ParseException(net.morimekta.providence.reflect.parser.ParseException) ConvertStream(net.morimekta.providence.tools.common.formats.ConvertStream) Argument(net.morimekta.console.args.Argument) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SocketClientHandler(net.morimekta.providence.thrift.client.SocketClientHandler) Flag(net.morimekta.console.args.Flag) PService(net.morimekta.providence.descriptor.PService) Map(java.util.Map) GenericUrl(com.google.api.client.http.GenericUrl) NonblockingSocketClientHandler(net.morimekta.providence.thrift.client.NonblockingSocketClientHandler) FormatUtils(net.morimekta.providence.tools.common.formats.FormatUtils) Strings(net.morimekta.util.Strings) ConvertStreamParser(net.morimekta.providence.tools.common.formats.ConvertStreamParser) URI(java.net.URI) Parser.oneOf(net.morimekta.console.util.Parser.oneOf) ArgumentParser(net.morimekta.console.args.ArgumentParser) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Serializer(net.morimekta.providence.serializer.Serializer) SerializerProvider(net.morimekta.providence.serializer.SerializerProvider) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) CProgram(net.morimekta.providence.reflect.contained.CProgram) HttpTransport(com.google.api.client.http.HttpTransport) PServiceCallHandler(net.morimekta.providence.PServiceCallHandler) SetHeadersInitializer(net.morimekta.providence.tools.rpc.utils.SetHeadersInitializer) Set(java.util.Set) CommonOptions(net.morimekta.providence.tools.common.CommonOptions) IOException(java.io.IOException) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) File(java.io.File) ArgumentException(net.morimekta.console.args.ArgumentException) List(java.util.List) STTY(net.morimekta.console.util.STTY) ThriftProgramParser(net.morimekta.providence.reflect.parser.ThriftProgramParser) Option(net.morimekta.console.args.Option) MessageReader(net.morimekta.providence.mio.MessageReader) Format(net.morimekta.providence.tools.common.formats.Format) TypeLoader(net.morimekta.providence.reflect.TypeLoader) Argument(net.morimekta.console.args.Argument) Option(net.morimekta.console.args.Option) ArgumentException(net.morimekta.console.args.ArgumentException) URISyntaxException(java.net.URISyntaxException) ArgumentParser(net.morimekta.console.args.ArgumentParser) Flag(net.morimekta.console.args.Flag) URI(java.net.URI) ConvertStreamParser(net.morimekta.providence.tools.common.formats.ConvertStreamParser)

Aggregations

Argument (net.morimekta.console.args.Argument)2 ArgumentParser (net.morimekta.console.args.ArgumentParser)2 Flag (net.morimekta.console.args.Flag)2 Option (net.morimekta.console.args.Option)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 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1