Last active
May 30, 2025 19:08
-
-
Save atifaziz/6db7e9c00f83a2783d28437fe7c991d1 to your computer and use it in GitHub Desktop.
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
<Query Kind="Statements"> | |
<NuGetReference Version="0.8.1">docopt.net</NuGetReference> | |
<Namespace>DocoptNet</Namespace> | |
</Query> | |
const string docopt = """ | |
Usage: | |
test.exe (-h | --help) | |
test.exe cmd [-abc] INPUT | |
"""; | |
var parser = | |
Docopt.CreateParser(docopt) | |
.WithVersion($"App v{Assembly.GetExecutingAssembly().GetName().Version}"); | |
var results = | |
from args in new string[][] | |
{ | |
[], // Error | |
["-h"], // Help | |
["--help"], // Help | |
[""], // Error | |
["foo"], // Error | |
["cmd"], // Error | |
["cmd", "foo"], // OK | |
["cmd", "-ac", "foo"], // OK | |
["cmd", "-a", "-c", "foo"], // OK | |
} | |
let result = | |
parser.Parse(args) | |
.Match(static args => (Outcome: "Args" , Arg: (object)args), | |
static result => (Outcome: "Help" , Arg: result), | |
static result => (Outcome: "Version", Arg: result), | |
static result => (Outcome: "Error" , Arg: result)) | |
select new | |
{ | |
Args = args, | |
result.Outcome, | |
Result = result.Arg, | |
}; | |
results. Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment