Skip to content

Instantly share code, notes, and snippets.

@adamralph
Last active October 17, 2019 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamralph/d6a3167c8fe0d4e24721d8d2b9c02989 to your computer and use it in GitHub Desktop.
Save adamralph/d6a3167c8fe0d4e24721d8d2b9c02989 to your computer and use it in GitHub Desktop.
Using Bullseye with custom args with McMaster.Extensions.CommandLineUtils
// 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