Last active
October 17, 2019 09:51
-
-
Save adamralph/d6a3167c8fe0d4e24721d8d2b9c02989 to your computer and use it in GitHub Desktop.
Using Bullseye with custom args with McMaster.Extensions.CommandLineUtils
This file contains 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
// dotnet add package McMaster.Extensions.CommandLineUtils | |
using System.Linq; | |
using McMaster.Extensions.CommandLineUtils; | |
using static Bullseye.Targets; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var app = new CommandLineApplication(throwOnUnexpectedArg: false); | |
var targets = app.Option<string>("--targets", "The targets to run or list.", CommandOptionType.MultipleValue); | |
var foo = app.Option<string>("--foo", "A value used for something.", CommandOptionType.SingleValue); | |
app.OnExecute(() => | |
{ | |
Target("build", () => System.Console.WriteLine($"foo = {foo.Value()}")); | |
Target("default", DependsOn("build")); | |
RunTargetsAndExit(targets.Values.Concat(app.RemainingArguments)); | |
}); | |
app.Execute(args); | |
} | |
} | |
// To run the default target: | |
// dotnet run -- --foo=bar | |
// | |
// To run a single specific target: | |
// dotnet run -- --target build --foo=bar | |
// | |
// To run multiple specific targets: | |
// dotnet run -- --target default --target build --foo=bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment