Created
October 31, 2016 14:07
-
-
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
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
#load "./customtool.cake" | |
#load "./mytools.cake" | |
GitStatus(); | |
GitBranch(new CustomToolSettings { ToolPath = "/bin/git.exe" }); |
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
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); | |
} |
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
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