Skip to content

Instantly share code, notes, and snippets.

@devlead
Created October 31, 2016 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devlead/2b3946ce051cc0d32fda56d4f92faabf to your computer and use it in GitHub Desktop.
Save devlead/2b3946ce051cc0d32fda56d4f92faabf to your computer and use it in GitHub Desktop.
Example of a custom Cake tool utilizing the in Cake built on tool classes, settings and tool resolution
#load "./customtool.cake"
#load "./mytools.cake"
GitStatus();
GitBranch(new CustomToolSettings { ToolPath = "/bin/git.exe" });
public class CustomToolSettings : Cake.Core.Tooling.ToolSettings
{
}
public class CustomTool : Cake.Core.Tooling.Tool<CustomToolSettings>
{
private readonly string _toolName;
private readonly string _exeName;
public static CustomToolHandler GetCustomAlias(ICakeContext context, string toolName, string exeName, Func<CustomToolSettings, ProcessArgumentBuilder> getArguments)
{
return (settings) => new CustomTool(
context,
toolName,
exeName
).Run(settings ?? new CustomToolSettings(), getArguments(settings));
}
protected override string GetToolName()
{
return _toolName;
}
protected override IEnumerable<string> GetToolExecutableNames()
{
return new[] { _exeName };
}
private CustomTool(ICakeContext context, string toolName, string exeName)
: base(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools)
{
_toolName = toolName;
_exeName = exeName;
}
public delegate void CustomToolHandler(CustomToolSettings settings = null);
}
var GitStatus = CustomTool.GetCustomAlias(Context, "git", "git.exe", settings=>"status");
var GitBranch = CustomTool.GetCustomAlias(Context, "git", "git.exe", settings=>"branch");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment