@@ -70,6 +70,9 @@ public abstract class BuildScript
7070 /// <returns>The exit code from this build script.</returns>
7171 public abstract int Run ( IBuildActions actions , Action < string , bool > startCallback , Action < int , string , bool > exitCallBack , BuildOutputHandler onOutput , BuildOutputHandler onError ) ;
7272
73+ /// <summary>
74+ /// A build script which executes an external program or script.
75+ /// </summary>
7376 private class BuildCommand : BuildScript
7477 {
7578 private readonly string exe , arguments ;
@@ -154,6 +157,9 @@ public override int Run(IBuildActions actions, Action<string, bool> startCallbac
154157
155158 }
156159
160+ /// <summary>
161+ /// A build script which runs a C# function.
162+ /// </summary>
157163 private class ReturnBuildCommand : BuildScript
158164 {
159165 private readonly Func < IBuildActions , int > func ;
@@ -333,6 +339,23 @@ public static BuildScript Bind(BuildScript s1, Func<IList<string>, int, BuildScr
333339 /// </summary>
334340 public static BuildScript Try ( BuildScript s ) => s | Success ;
335341
342+ /// <summary>
343+ /// Creates a build script that runs the build script <paramref name="s" />. If
344+ /// running <paramref name="s" /> fails, <paramref name="k" /> is invoked with
345+ /// the exit code.
346+ /// </summary>
347+ /// <param name="s">The build script to run.</param>
348+ /// <param name="k">
349+ /// The callback that is invoked if <paramref name="s" /> failed.
350+ /// </param>
351+ /// <returns>The build script which implements this.</returns>
352+ public static BuildScript OnFailure ( BuildScript s , Action < int > k ) =>
353+ new BindBuildScript ( s , ret => Create ( actions =>
354+ {
355+ if ( ! Succeeded ( ret ) ) k ( ret ) ;
356+ return ret ;
357+ } ) ) ;
358+
336359 /// <summary>
337360 /// Creates a build script that deletes the given directory.
338361 /// </summary>
0 commit comments