Created
March 31, 2022 20:05
-
-
Save atifaziz/636f661bb8ca1ae75536f4c7834af2ef to your computer and use it in GitHub Desktop.
Code generated by docopt.net for dotnet-file's usage
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 Devlooped | |
{ | |
partial class ProgramArguments : IEnumerable<KeyValuePair<string, object?>> | |
{ | |
public const string Help = @"Usage: | |
dotnet-file (add|changes|delete|init|list) <file-or-url>... | |
dotnet-file (sync|update) <file-or-url>... [--changelog=<md-file>] | |
dotnet-file --version | |
dotnet-file -h | --help | |
Actions: | |
add downloads a file or GitHub repository or directory from a URL | |
changes checks remote URLs for changes and lists the status of local files | |
delete deletes a file and its corresponding config entry from the local directory | |
init initializes the local directory from one or more remote .netconfig files | |
list lists the config entries and the status of their corresponding files | |
sync synchronizes with remote URLs, deleting local files and directories as needed | |
update updates local files from remote URLs, does not prune deleted remote files | |
Options: | |
-c, --changelog=<md-file> | |
generate Markdown file with links to commits for updated files | |
[default: dotnet-file.md] | |
-h, --help show this screen | |
--version show version | |
Status: | |
= <- [url] remote file equals local file | |
✓ <- [url] local file updated with remote file | |
^ <- [url] remote file is newer (ETags mismatch) | |
? <- [url] local file not found for remote file | |
x <- [url] error processing the entry | |
"; | |
public const string Usage = @"Usage: | |
dotnet-file (add|changes|delete|init|list) <file-or-url>... | |
dotnet-file (sync|update) <file-or-url>... [--changelog=<md-file>] | |
dotnet-file --version | |
dotnet-file -h | --help"; | |
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("-c", "--changelog", 1, "dotnet-file.md"), | |
new("-h", "--help", 0, false), | |
new(null, "--version", 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 "add": result.CmdAdd = (bool)value; break; | |
case "changes": result.CmdChanges = (bool)value; break; | |
case "delete": result.CmdDelete = (bool)value; break; | |
case "init": result.CmdInit = (bool)value; break; | |
case "list": result.CmdList = (bool)value; break; | |
case "<file-or-url>": result.ArgFileOrUrl = (StringList)value; break; | |
case "sync": result.CmdSync = (bool)value; break; | |
case "update": result.CmdUpdate = (bool)value; break; | |
case "--changelog": result.OptChangelog = (string)value; break; | |
case "--version": result.OptVersion = (bool)value; break; | |
case "--help": result.OptHelp = (bool)value; break; | |
} | |
} | |
return GeneratedSourceModule.CreateArgumentsResult(result); | |
} | |
static void Match(ref RequiredMatcher required) | |
{ | |
// Required(Either(Required(Required(Either(Command(add, False), Command(changes, False), Command(delete, False), Command(init, False), Command(list, False))), OneOrMore(Argument(<file-or-url>, []))), Required(Required(Either(Command(sync, False), Command(update, False))), OneOrMore(Argument(<file-or-url>, [])), Optional(Option(-c,--changelog,1,dotnet-file.md))), Required(Option(,--version,0,False)), Required(Option(-h,--help,0,False)))) | |
var a = new RequiredMatcher(1, required.Left, required.Collected); | |
while (a.Next()) | |
{ | |
// Either(Required(Required(Either(Command(add, False), Command(changes, False), Command(delete, False), Command(init, False), Command(list, False))), OneOrMore(Argument(<file-or-url>, []))), Required(Required(Either(Command(sync, False), Command(update, False))), OneOrMore(Argument(<file-or-url>, [])), Optional(Option(-c,--changelog,1,dotnet-file.md))), Required(Option(,--version,0,False)), Required(Option(-h,--help,0,False))) | |
var b = new EitherMatcher(4, a.Left, a.Collected); | |
while (b.Next()) | |
{ | |
switch (b.Index) | |
{ | |
case 0: | |
{ | |
// Required(Required(Either(Command(add, False), Command(changes, False), Command(delete, False), Command(init, False), Command(list, False))), OneOrMore(Argument(<file-or-url>, []))) | |
var c = new RequiredMatcher(2, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
switch (c.Index) | |
{ | |
case 0: | |
{ | |
// Required(Either(Command(add, False), Command(changes, False), Command(delete, False), Command(init, False), Command(list, False))) | |
var d = new RequiredMatcher(1, c.Left, c.Collected); | |
while (d.Next()) | |
{ | |
// Either(Command(add, False), Command(changes, False), Command(delete, False), Command(init, False), Command(list, False)) | |
var e = new EitherMatcher(5, d.Left, d.Collected); | |
while (e.Next()) | |
{ | |
switch (e.Index) | |
{ | |
case 0: | |
{ | |
// Command(add, False) | |
e.Match(PatternMatcher.MatchCommand, "add", ArgValueKind.Boolean); | |
} | |
break; | |
case 1: | |
{ | |
// Command(changes, False) | |
e.Match(PatternMatcher.MatchCommand, "changes", ArgValueKind.Boolean); | |
} | |
break; | |
case 2: | |
{ | |
// Command(delete, False) | |
e.Match(PatternMatcher.MatchCommand, "delete", ArgValueKind.Boolean); | |
} | |
break; | |
case 3: | |
{ | |
// Command(init, False) | |
e.Match(PatternMatcher.MatchCommand, "init", ArgValueKind.Boolean); | |
} | |
break; | |
case 4: | |
{ | |
// Command(list, False) | |
e.Match(PatternMatcher.MatchCommand, "list", ArgValueKind.Boolean); | |
} | |
break; | |
} | |
if (!e.LastMatched) | |
{ | |
break; | |
} | |
} | |
d.Fold(e.Result); | |
if (!d.LastMatched) | |
{ | |
break; | |
} | |
} | |
c.Fold(d.Result); | |
} | |
break; | |
case 1: | |
{ | |
// OneOrMore(Argument(<file-or-url>, [])) | |
var d = new OneOrMoreMatcher(1, c.Left, c.Collected); | |
while (d.Next()) | |
{ | |
// Argument(<file-or-url>, []) | |
d.Match(PatternMatcher.MatchArgument, "<file-or-url>", ArgValueKind.StringList); | |
if (!d.LastMatched) | |
{ | |
break; | |
} | |
} | |
c.Fold(d.Result); | |
} | |
break; | |
} | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
case 1: | |
{ | |
// Required(Required(Either(Command(sync, False), Command(update, False))), OneOrMore(Argument(<file-or-url>, [])), Optional(Option(-c,--changelog,1,dotnet-file.md))) | |
var c = new RequiredMatcher(3, b.Left, b.Collected); | |
while (c.Next()) | |
{ | |
switch (c.Index) | |
{ | |
case 0: | |
{ | |
// Required(Either(Command(sync, False), Command(update, False))) | |
var d = new RequiredMatcher(1, c.Left, c.Collected); | |
while (d.Next()) | |
{ | |
// Either(Command(sync, False), Command(update, False)) | |
var e = new EitherMatcher(2, d.Left, d.Collected); | |
while (e.Next()) | |
{ | |
switch (e.Index) | |
{ | |
case 0: | |
{ | |
// Command(sync, False) | |
e.Match(PatternMatcher.MatchCommand, "sync", ArgValueKind.Boolean); | |
} | |
break; | |
case 1: | |
{ | |
// Command(update, False) | |
e.Match(PatternMatcher.MatchCommand, "update", ArgValueKind.Boolean); | |
} | |
break; | |
} | |
if (!e.LastMatched) | |
{ | |
break; | |
} | |
} | |
d.Fold(e.Result); | |
if (!d.LastMatched) | |
{ | |
break; | |
} | |
} | |
c.Fold(d.Result); | |
} | |
break; | |
case 1: | |
{ | |
// OneOrMore(Argument(<file-or-url>, [])) | |
var d = new OneOrMoreMatcher(1, c.Left, c.Collected); | |
while (d.Next()) | |
{ | |
// Argument(<file-or-url>, []) | |
d.Match(PatternMatcher.MatchArgument, "<file-or-url>", ArgValueKind.StringList); | |
if (!d.LastMatched) | |
{ | |
break; | |
} | |
} | |
c.Fold(d.Result); | |
} | |
break; | |
case 2: | |
{ | |
// Optional(Option(-c,--changelog,1,dotnet-file.md)) | |
var d = new OptionalMatcher(1, c.Left, c.Collected); | |
while (d.Next()) | |
{ | |
// Option(-c,--changelog,1,dotnet-file.md) | |
d.Match(PatternMatcher.MatchOption, "--changelog", ArgValueKind.String); | |
if (!d.LastMatched) | |
{ | |
break; | |
} | |
} | |
c.Fold(d.Result); | |
} | |
break; | |
} | |
if (!c.LastMatched) | |
{ | |
break; | |
} | |
} | |
b.Fold(c.Result); | |
} | |
break; | |
case 2: | |
{ | |
// 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; | |
case 3: | |
{ | |
// 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; | |
} | |
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("add", (object?)CmdAdd); | |
yield return KeyValuePair.Create("changes", (object?)CmdChanges); | |
yield return KeyValuePair.Create("delete", (object?)CmdDelete); | |
yield return KeyValuePair.Create("init", (object?)CmdInit); | |
yield return KeyValuePair.Create("list", (object?)CmdList); | |
yield return KeyValuePair.Create("<file-or-url>", (object?)ArgFileOrUrl); | |
yield return KeyValuePair.Create("sync", (object?)CmdSync); | |
yield return KeyValuePair.Create("update", (object?)CmdUpdate); | |
yield return KeyValuePair.Create("--changelog", (object?)OptChangelog); | |
yield return KeyValuePair.Create("--version", (object?)OptVersion); | |
yield return KeyValuePair.Create("--help", (object?)OptHelp); | |
} | |
IEnumerator<KeyValuePair<string, object?>> IEnumerable<KeyValuePair<string, object?>>.GetEnumerator() => GetEnumerator(); | |
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | |
/// <summary><c>Command(add, False)</c></summary> | |
public bool CmdAdd { get; private set; } | |
/// <summary><c>Command(changes, False)</c></summary> | |
public bool CmdChanges { get; private set; } | |
/// <summary><c>Command(delete, False)</c></summary> | |
public bool CmdDelete { get; private set; } | |
/// <summary><c>Command(init, False)</c></summary> | |
public bool CmdInit { get; private set; } | |
/// <summary><c>Command(list, False)</c></summary> | |
public bool CmdList { get; private set; } | |
/// <summary><c>Argument(<file-or-url>, [])</c></summary> | |
public StringList ArgFileOrUrl { get; private set; } = StringList.Empty; | |
/// <summary><c>Command(sync, False)</c></summary> | |
public bool CmdSync { get; private set; } | |
/// <summary><c>Command(update, False)</c></summary> | |
public bool CmdUpdate { get; private set; } | |
/// <summary><c>Option(-c,--changelog,1,dotnet-file.md)</c></summary> | |
public string OptChangelog { get; private set; } = "dotnet-file.md"; | |
/// <summary><c>Option(,--version,0,False)</c></summary> | |
public bool OptVersion { get; private set; } | |
/// <summary><c>Option(-h,--help,0,False)</c></summary> | |
public bool OptHelp { get; private set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment