Last active
April 4, 2022 17:26
-
-
Save atifaziz/dbca5ef0c719fa9900eaefecc912fbce to your computer and use it in GitHub Desktop.
Code generated by docopt.net for Vipr's usage; see https://github.com/microsoft/Vipr
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 Vipr | |
{ | |
partial class Bootstrapper | |
{ | |
partial class Arguments : IEnumerable<KeyValuePair<string, object?>> | |
{ | |
public const string Usage = @"Usage: | |
vipr.exe <inputFile> [--reader=<readerName>] [--writer=<writerName>] [--outputPath=<outputPath>] [--modelExport=<modelExportPath>]"; | |
static readonly IBaselineParser<Arguments> Parser = GeneratedSourceModule.CreateParser(Help, Parse); | |
public static IBaselineParser<Arguments> CreateParser() => Parser; | |
static IParser<Arguments>.IResult Parse(IEnumerable<string> args, ParseFlags flags, string? version) | |
{ | |
var options = new List<Option> | |
{ | |
new(null, "--reader", 1, null), | |
new(null, "--writer", 1, null), | |
new(null, "--outputPath", 1, null), | |
new(null, "--modelExport", 1, null), | |
}; | |
return GeneratedSourceModule.Parse(Help, Usage, args, options, flags, version, Parse); | |
static IParser<Arguments>.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<Arguments>(string.Empty, Usage); | |
} | |
var collected = required.Collected; | |
var result = new Arguments(); | |
foreach (var leaf in collected) | |
{ | |
var value = leaf.Value is { IsStringList: true } ? ((StringList)leaf.Value).Reverse() : leaf.Value; | |
switch (leaf.Name) | |
{ | |
case "<inputFile>": result.ArgInputfile = (string?)value; break; | |
case "--reader": result.OptReader = (string?)value; break; | |
case "--writer": result.OptWriter = (string?)value; break; | |
case "--outputPath": result.OptOutputpath = (string?)value; break; | |
case "--modelExport": result.OptModelexport = (string?)value; break; | |
} | |
} | |
return GeneratedSourceModule.CreateArgumentsResult(result); | |
} | |
static void Match(ref RequiredMatcher required) | |
{ | |
// Required(Required(Argument(<inputFile>, ), Optional(Option(,--reader,1,)), Optional(Option(,--writer,1,)), Optional(Option(,--outputPath,1,)), Optional(Option(,--modelExport,1,)))) | |
var a = new RequiredMatcher(1, required.Left, required.Collected); | |
while (a.Next()) | |
{ | |
// Required(Argument(<inputFile>, ), Optional(Option(,--reader,1,)), Optional(Option(,--writer,1,)), Optional(Option(,--outputPath,1,)), Optional(Option(,--modelExport,1,))) | |
var b = new RequiredMatcher(5, a.Left, a.Collected); | |
while (b.Next()) | |
{ | |
switch (b.Index) | |
{ | |
case 0: | |
{ | |
// Argument(<inputFile>, ) | |
b.Match(PatternMatcher.MatchArgument, "<inputFile>", ArgValueKind.None); | |
} | |
break; | |
case 1: | |
{ | |
// Optional(Option(,--reader,1,)) | |
var c = new OptionalMatcher(1, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
// Option(,--reader,1,) | |
c.Match(PatternMatcher.MatchOption, "--reader", ArgValueKind.None); | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
case 2: | |
{ | |
// Optional(Option(,--writer,1,)) | |
var c = new OptionalMatcher(1, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
// Option(,--writer,1,) | |
c.Match(PatternMatcher.MatchOption, "--writer", ArgValueKind.None); | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
case 3: | |
{ | |
// Optional(Option(,--outputPath,1,)) | |
var c = new OptionalMatcher(1, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
// Option(,--outputPath,1,) | |
c.Match(PatternMatcher.MatchOption, "--outputPath", ArgValueKind.None); | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
case 4: | |
{ | |
// Optional(Option(,--modelExport,1,)) | |
var c = new OptionalMatcher(1, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
// Option(,--modelExport,1,) | |
c.Match(PatternMatcher.MatchOption, "--modelExport", ArgValueKind.None); | |
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("<inputFile>", (object?)ArgInputfile); | |
yield return KeyValuePair.Create("--reader", (object?)OptReader); | |
yield return KeyValuePair.Create("--writer", (object?)OptWriter); | |
yield return KeyValuePair.Create("--outputPath", (object?)OptOutputpath); | |
yield return KeyValuePair.Create("--modelExport", (object?)OptModelexport); | |
} | |
IEnumerator<KeyValuePair<string, object?>> IEnumerable<KeyValuePair<string, object?>>.GetEnumerator() => GetEnumerator(); | |
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | |
/// <summary><c>Argument(<inputFile>, )</c></summary> | |
public string? ArgInputfile { get; private set; } | |
/// <summary><c>Option(,--reader,1,)</c></summary> | |
public string? OptReader { get; private set; } | |
/// <summary><c>Option(,--writer,1,)</c></summary> | |
public string? OptWriter { get; private set; } | |
/// <summary><c>Option(,--outputPath,1,)</c></summary> | |
public string? OptOutputpath { get; private set; } | |
/// <summary><c>Option(,--modelExport,1,)</c></summary> | |
public string? OptModelexport { get; private set; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment