Created
June 18, 2022 17:02
-
-
Save atifaziz/a1274a60a21403e391638e3e01e7e5f9 to your computer and use it in GitHub Desktop.
Code generated by docopt.net for grpc-curl's usage; see https://github.com/xoofx/grpc-curl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#nullable enable annotations | |
using System.Collections; | |
using System.Collections.Generic; | |
using DocoptNet; | |
using DocoptNet.Internals; | |
using Leaves = DocoptNet.Internals.ReadOnlyList<DocoptNet.Internals.LeafPattern>; | |
namespace GrpcCurl | |
{ | |
partial class ProgramArguments : IEnumerable<KeyValuePair<string, object?>> | |
{ | |
public const string Help = @"grpc-curl {version} - 2022 (c) Copyright Alexandre Mutel | |
Usage: | |
grpc-curl <address:port> <service/method> [--data=<json_string>] | |
[--http] [--json] | |
grpc-curl describe <address:port> <service> | |
grpc-curl -h | --help | |
grpc-curl --version | |
Sub-commands: | |
describe Describe the service or dump all services available. | |
Options: | |
--version Show version information. | |
-h, --help Show help information. | |
-d, --data=<json_string> JSON string to send as a message. | |
--http Use HTTP instead of HTTPS unless the | |
protocol is specified directly on the address. | |
--json Use JSON naming for input and output. | |
"; | |
public const string Usage = @"Usage: | |
grpc-curl <address:port> <service/method> [--data=<json_string>] | |
[--http] [--json] | |
grpc-curl describe <address:port> <service> | |
grpc-curl -h | --help | |
grpc-curl --version"; | |
static readonly IHelpFeaturingParser<ProgramArguments> Parser = GeneratedSourceModule.CreateParser(Help, Parse).EnableHelp(); | |
public static IHelpFeaturingParser<ProgramArguments> CreateParser() => Parser; | |
static IParser<ProgramArguments>.IResult Parse(IEnumerable<string> args, ParseFlags flags, string? version) | |
{ | |
var options = new List<Option> | |
{ | |
new(null, "--version", 0, false), | |
new("-h", "--help", 0, false), | |
new("-d", "--data", 1, null), | |
new(null, "--http", 0, false), | |
new(null, "--json", 0, false), | |
}; | |
return GeneratedSourceModule.Parse(Help, Usage, args, options, flags, version, Parse); | |
static IParser<ProgramArguments>.IResult Parse(Leaves left) | |
{ | |
var required = new RequiredMatcher(1, left, new Leaves()); | |
Match(ref required); | |
if (!required.Result || required.Left.Count > 0) | |
{ | |
return GeneratedSourceModule.CreateInputErrorResult<ProgramArguments>(string.Empty, Usage); | |
} | |
var collected = required.Collected; | |
var result = new ProgramArguments(); | |
foreach (var leaf in collected) | |
{ | |
var value = leaf.Value is { IsStringList: true } ? ((StringList)leaf.Value).Reverse() : leaf.Value; | |
switch (leaf.Name) | |
{ | |
case "<address:port>": result.ArgAddressColonPort = (string?)value; break; | |
case "<service/method>": result.ArgServiceSlashMethod = (string?)value; break; | |
case "--data": result.OptData = (string?)value; break; | |
case "--http": result.OptHttp = (bool)value; break; | |
case "--json": result.OptJson = (bool)value; break; | |
case "describe": result.CmdDescribe = (bool)value; break; | |
case "<service>": result.ArgService = (string?)value; break; | |
case "--help": result.OptHelp = (bool)value; break; | |
case "--version": result.OptVersion = (bool)value; break; | |
} | |
} | |
return GeneratedSourceModule.CreateArgumentsResult(result); | |
} | |
static void Match(ref RequiredMatcher required) | |
{ | |
// Required(Either(Required(Argument(<address:port>, ), Argument(<service/method>, ), Optional(Option(-d,--data,1,)), Optional(Option(,--http,0,False)), Optional(Option(,--json,0,False))), Required(Command(describe, False), Argument(<address:port>, ), Argument(<service>, )), Required(Option(-h,--help,0,False)), Required(Option(,--version,0,False)))) | |
var a = new RequiredMatcher(1, required.Left, required.Collected); | |
while (a.Next()) | |
{ | |
// Either(Required(Argument(<address:port>, ), Argument(<service/method>, ), Optional(Option(-d,--data,1,)), Optional(Option(,--http,0,False)), Optional(Option(,--json,0,False))), Required(Command(describe, False), Argument(<address:port>, ), Argument(<service>, )), Required(Option(-h,--help,0,False)), Required(Option(,--version,0,False))) | |
var b = new EitherMatcher(4, a.Left, a.Collected); | |
while (b.Next()) | |
{ | |
switch (b.Index) | |
{ | |
case 0: | |
{ | |
// Required(Argument(<address:port>, ), Argument(<service/method>, ), Optional(Option(-d,--data,1,)), Optional(Option(,--http,0,False)), Optional(Option(,--json,0,False))) | |
var c = new RequiredMatcher(5, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
switch (c.Index) | |
{ | |
case 0: | |
{ | |
// Argument(<address:port>, ) | |
c.Match(PatternMatcher.MatchArgument, "<address:port>", ArgValueKind.None); | |
} | |
break; | |
case 1: | |
{ | |
// Argument(<service/method>, ) | |
c.Match(PatternMatcher.MatchArgument, "<service/method>", ArgValueKind.None); | |
} | |
break; | |
case 2: | |
{ | |
// Optional(Option(-d,--data,1,)) | |
var d = new OptionalMatcher(1, c.Left, c.Collected); | |
while (d.Next()) | |
{ | |
// Option(-d,--data,1,) | |
d.Match(PatternMatcher.MatchOption, "--data", ArgValueKind.None); | |
if (!d.LastMatched) | |
{ | |
break; | |
} | |
} | |
c.Fold(d.Result); | |
} | |
break; | |
case 3: | |
{ | |
// Optional(Option(,--http,0,False)) | |
var d = new OptionalMatcher(1, c.Left, c.Collected); | |
while (d.Next()) | |
{ | |
// Option(,--http,0,False) | |
d.Match(PatternMatcher.MatchOption, "--http", ArgValueKind.Boolean); | |
if (!d.LastMatched) | |
{ | |
break; | |
} | |
} | |
c.Fold(d.Result); | |
} | |
break; | |
case 4: | |
{ | |
// Optional(Option(,--json,0,False)) | |
var d = new OptionalMatcher(1, c.Left, c.Collected); | |
while (d.Next()) | |
{ | |
// Option(,--json,0,False) | |
d.Match(PatternMatcher.MatchOption, "--json", ArgValueKind.Boolean); | |
if (!d.LastMatched) | |
{ | |
break; | |
} | |
} | |
c.Fold(d.Result); | |
} | |
break; | |
} | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
case 1: | |
{ | |
// Required(Command(describe, False), Argument(<address:port>, ), Argument(<service>, )) | |
var c = new RequiredMatcher(3, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
switch (c.Index) | |
{ | |
case 0: | |
{ | |
// Command(describe, False) | |
c.Match(PatternMatcher.MatchCommand, "describe", ArgValueKind.Boolean); | |
} | |
break; | |
case 1: | |
{ | |
// Argument(<address:port>, ) | |
c.Match(PatternMatcher.MatchArgument, "<address:port>", ArgValueKind.None); | |
} | |
break; | |
case 2: | |
{ | |
// Argument(<service>, ) | |
c.Match(PatternMatcher.MatchArgument, "<service>", ArgValueKind.None); | |
} | |
break; | |
} | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
case 2: | |
{ | |
// Required(Option(-h,--help,0,False)) | |
var c = new RequiredMatcher(1, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
// Option(-h,--help,0,False) | |
c.Match(PatternMatcher.MatchOption, "--help", ArgValueKind.Boolean); | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
case 3: | |
{ | |
// Required(Option(,--version,0,False)) | |
var c = new RequiredMatcher(1, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
// Option(,--version,0,False) | |
c.Match(PatternMatcher.MatchOption, "--version", ArgValueKind.Boolean); | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
} | |
if (!b.LastMatched) | |
{ | |
break; | |
} | |
} | |
a.Fold(b.Result); | |
if (!a.LastMatched) | |
{ | |
break; | |
} | |
} | |
required.Fold(a.Result); | |
} | |
} | |
IEnumerator<KeyValuePair<string, object?>> GetEnumerator() | |
{ | |
yield return KeyValuePair.Create("<address:port>", (object?)ArgAddressColonPort); | |
yield return KeyValuePair.Create("<service/method>", (object?)ArgServiceSlashMethod); | |
yield return KeyValuePair.Create("--data", (object?)OptData); | |
yield return KeyValuePair.Create("--http", (object?)OptHttp); | |
yield return KeyValuePair.Create("--json", (object?)OptJson); | |
yield return KeyValuePair.Create("describe", (object?)CmdDescribe); | |
yield return KeyValuePair.Create("<service>", (object?)ArgService); | |
yield return KeyValuePair.Create("--help", (object?)OptHelp); | |
yield return KeyValuePair.Create("--version", (object?)OptVersion); | |
} | |
IEnumerator<KeyValuePair<string, object?>> IEnumerable<KeyValuePair<string, object?>>.GetEnumerator() => GetEnumerator(); | |
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | |
/// <summary><c>Argument(<address:port>, )</c></summary> | |
public string? ArgAddressColonPort { get; private set; } | |
/// <summary><c>Argument(<service/method>, )</c></summary> | |
public string? ArgServiceSlashMethod { get; private set; } | |
/// <summary><c>Option(-d,--data,1,)</c></summary> | |
public string? OptData { get; private set; } | |
/// <summary><c>Option(,--http,0,False)</c></summary> | |
public bool OptHttp { get; private set; } | |
/// <summary><c>Option(,--json,0,False)</c></summary> | |
public bool OptJson { get; private set; } | |
/// <summary><c>Command(describe, False)</c></summary> | |
public bool CmdDescribe { get; private set; } | |
/// <summary><c>Argument(<service>, )</c></summary> | |
public string? ArgService { get; private set; } | |
/// <summary><c>Option(-h,--help,0,False)</c></summary> | |
public bool OptHelp { get; private set; } | |
/// <summary><c>Option(,--version,0,False)</c></summary> | |
public bool OptVersion { get; private set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment