Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robgha01/bc7ff1a21f18183ade7943819f7ec477 to your computer and use it in GitHub Desktop.
Save robgha01/bc7ff1a21f18183ade7943819f7ec477 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using Cake.Core;
using Cake.Core.Annotations;
using JetBrains.Annotations;
/// <summary>
/// NuGetPackSettings extensions.
/// </summary>
public static class CakeCoreExtensions
{
/// <summary>
/// The get cake options.
/// </summary>
/// <param name="context">
/// The context.
/// </param>
/// <returns>
/// A <see cref="IEnumerable{KeyValuePair}"/> containing
/// the parsed cake arguments.
/// </returns>
[CakeMethodAlias]
[CakeNamespaceImport("BlueLeet.Build.Extensions")]
[UsedImplicitly]
public static IEnumerable<KeyValuePair<string, string>> GetCakeOptions(this ICakeContext context)
{
var result = new Dictionary<string, string>();
var args = Environment.GetCommandLineArgs().Skip(1).ToList();
// Include the script argument.
result.Add("-script", args[0]);
// Include the rest of the arguments.
foreach (var arg in args.Skip(1).Where(x => x.SingleOrDefault(c => c == '=') != default(char)).Select(x => x.Split('=')))
{
result.Add(arg[0], arg[1]);
}
return result;
}
}
@robgha01
Copy link
Author

The output is this.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment